samedi 9 mai 2015

I want to generate this textbox with a model's I.d when i'm creating and also making the textbox uneditable

This is my model

    [Key]
    public int ConsultId { get; set; }

`

This is my View `

    @Html.LabelFor(model => model.ConsultId, htmlAttributes: new { @class = "control-label col-md-2" })

        @Html.IdFor(m=>m.ConsultId)

        @Html.ValidationMessageFor(model => model.ConsultId, "", new { @class = "text-danger" })

What I want to do is,i want the textbox for the ConsultId to be autogenerated

downgrade jquery version on specific view only

let's say that I'm using jquery version 1.10 inside _Layout.cshtml and on specific pages to downgrade to 1.7.2.

How can I do this without changing Layout on this specific views? Is this even possible ? :)

custom identity user and extending profile MVC

I am trying to extend the identity user data in separate table but its not populating.

  public class MyUserInfo
  {
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

  }

  public class AppUser : IdentityUser<Int32, AppUserLogin, AppUserRole, AppUserClaim>
  {

    public MyUserInfo MyUserInfo { get; set; }
 }

//Fetching the user data

var userStore = new UserStore<AppUser, AppRole, int, AppUserLogin, AppUserRole, AppUserClaim>(db);
var userManager = new UserManager<AppUser, int>(userStore);

var user = userManager.FindById(1);
**user.MyUserInfo** showing the null. But in db, we have the respective user data.

I saw many post where without customization seems working but for me I modified id stored as integer and changed the table name.

ASP.Net Create Two Models With One Controller

I'm just trying To create one controller that will work with two models. Comment Model:

 public class Comment
 {
    public int ID { get; set; } // property
    public int PostID { get; set; }
    public String Title { get; set; }
    public String Name { get; set; }
    public Uri Url { get; set; }
    public String Text { get; set; }
    public Post Post { get; set; }
}

public class CommentDBContext : DbContext 
{
    public DbSet<Comment> Comments { get; set; }

    public System.Data.Entity.DbSet<BlogShauli.Models.Post> Posts { get; set; }

}

Post Model:

  public class Post
  {
    public int ID { get; set; } // property
    public String Title { get; set; }
    public String Author { get; set; }
    public String AuthorSite { get; set; }
    public DateTime ReleaseDate { get; set; }
    public String Text { get; set; }
 }

public class PostDBContext : DbContext
{
    public DbSet<Post> Posts { get; set; }
}

And now I want to create a Single Controller that will work with both models. I read that the way to do it is to use ViewModel Pattern so i created one more model class named "BlogViewModel.cs", with the following code:

public class MotorcycleViewModel
 {
     public Comment CommentPointer { get; set; }
     public Post PostPointer { get; set; }
 }

But from here i didn't understand what do. i'm trying to create a new Controller using Entity framework but i don't know what to select in the "Data context class". can someone would explain me how to make the connection between Both models and the Controller? Thanks!

The cast to value type 'System.Int32' failed because the materialized value is null

I have a Issue that I don't know what it is, there is my Home Controller:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Biblioteca.Models;
using CrystalDecisions.CrystalReports.Engine;

namespace Biblioteca.Controllers
{
public class HomeController : Controller
{
    private BibliotecaDatabase db = new BibliotecaDatabase();

    public ActionResult Index()
    {
        var totalesviewmodel = new TotalesViewModel();
        totalesviewmodel.MontoCopias = db.AlumnosList.Sum(o => o.Copias);
        totalesviewmodel.MontoImpresiones = db.AlumnosList.Sum(o => o.Impresiones);
        totalesviewmodel.DineroDeposito = db.AlumnosList.Sum(o => o.Deposito);
        totalesviewmodel.DineroSap = db.AlumnosList.Sum(o => o.Sap);
// there is my issue
        totalesviewmodel.MontoCopiasMaestro = db.MaestrosList.Sum(o  => o.Copias );
        totalesviewmodel.MontoImpresionesMaestro = db.MaestrosList.Sum(o => o.Impresiones);
        return View(totalesviewmodel);
    }

    public ActionResult Reports()
    {
        List<Alumno> allDatos = new List<Alumno>();
        using (BibliotecaEntities dc = new BibliotecaEntities())
        {
            allDatos = dc.Alumnos.ToList();


        }
        return View(allDatos);
    }

    public ActionResult ExportReport()
    {
        List<Alumno> allDatos = new List<Alumno>();
        using (BibliotecaEntities dc = new BibliotecaEntities())
        {
            allDatos = dc.Alumnos.ToList();



            ReportDocument rd = new ReportDocument();
            rd.Load(Path.Combine(Server.MapPath("~/Reports"), "rpt_datos.rpt"));
            rd.SetDataSource(allDatos);

            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            try
            {
                Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stream.Seek(0, SeekOrigin.Begin);
                return File(stream, "application/pdf", "Reporte.pdf");
            }
            catch (Exception ex)
            {

                throw;
            }
        }
    }

    public ActionResult Contact ()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}

So, I don't know why I have this issue on:

totalesviewmodel.MontoCopiasMaestro = db.MaestrosList.Sum(o  => o.Copias );

before install crystal reports I don't have this issue, can any one help me?

What am I doing wrong?

ASP vNext deployed on Azure does not render static files with a catch all rule

I just deployed for the first time a Single Page Application on azure which is based on ASP vNext and AngularJs.

I have created two rules for my routes.

The first one is for my APIs and the second is to catch all other requests which will show the Layout.cshtml and then be handled by Angular.

On my local machine, everything is working fine, but on azure, my static files shows the Layout.cshtml file like if it is catched by the catch all rule even though I specified in the Startup.cs file that I wanted ASP to handle static files.

Did anyone encountered that problem before ? And if yes, what would be the solution to fix this ?

Thanks.

app.UseStaticFiles(option);

// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "WebApi",
        template: "api/{controller}/{action}/{id?}");

    routes.MapRoute(
        "Default", // Route name
        "{*url}", // URL with parameters
        new { controller = "Home", action = "Index" } // Parameter defaults
    );
});

jquery onload select days

I'm using this plugin to select multiple week days from the user. As I can see everything is setup correctly, I can select days, save that data to the db and on editing I can retrieve data back to the ui, but problem is that this data is correctly loaded on edit mode inside ui but it's not selected on week days ui control.

1 picture is saying more that 1000 words :)

on load data (edit mode) this is current situation enter image description here

but should be like this enter image description here

this input with id DaysOfWeekSelected once setup correctly will be hidden by default.

Knowing all this and having data already inside view how can select this days from index (0,5,6) into plugin?

Just to mention that all scripts are loaded correctly, plugin works correctly on user selection (change days).

Update: I tried with some dummy data select days on page load using

$("#repeatOnDays").weekLine("setSelected", "0,1,2,3,4");

anyone to help?