I'm new to ASP.NET and can't manage to find any solution nor related thread to my issue.
I want to update an user in database with a onesignal unique identifier via an action method that is getting the current connected User.
I am using database first approach.
I get the following error when launching the request:
System.InvalidOperationException: The entity type PartenaireResult is not part of the model for the current context.
The thing is that PartenaireResult is not an entity on my table, only a class for returning datas.
I tried this solution with no luck (only adding another connection string named "DefaultConnection", but I don't understand the concept of NinjectWebCommons.
I also tried to put this coe in my DbContext class with no luck as stated in this thread:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<PartenaireResult>().ToTable("PartenaireResult");
}
Here is the non working method:
[Authorize(Roles = "partenaire")]
[Route("api/Partenaires/Me")]
public PartenaireResult GetClientsMe(string onesignal_id)
{
var connectedUser = GetConnectedUser(User);
connectedUser.onesignal_id = onesignal_id;
db.Entry(connectedUser).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
return connectedUser;
}
[Authorize(Roles = "partenaire")]
public static PartenaireResult GetConnectedUser(IPrincipal user)
{
var claimIdentity = user.Identity as ClaimsIdentity;
var claim = claimIdentity?.Claims?.FirstOrDefault(x => x.Type.Equals("IdClient", StringComparison.InvariantCultureIgnoreCase));
if (claim != null)
{
int idPartenaire;
if (int.TryParse(claim.Value, out idPartenaire))
{
using (var db = new UphairDbEntities())
{
var me = db.Partenaires.Find(idPartenaire);
PartenaireResult PartenaireRes = new PartenaireResult();
ObjectConverterHelper.CopyProperties(me, PartenaireRes);
return PartenaireRes;
}
}
}
return null;
}
Here's my PartenaireResult
class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Web;
using Uphair.EfModel;
namespace Uphair.Api.Models.Partenaire
{
public class PartenaireResult
{
public PartenaireResult()
{
}
public int IdPartenaire { get; set; }
public string NomComplet { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string PasswordSalt { get; set; }
public PartenaireType Type { get; set; }
public string Pays { get; set; }
public string Ville { get; set; }
public string CodePostale { get; set; }
public string Adresse { get; set; }
public Nullable<double> Lat { get; set; }
public Nullable<double> Lng { get; set; }
public string ImageUrl { get; set; }
public string CouvertureUrl { get; set; }
public string TelMobile { get; set; }
public Nullable<System.DateTime> DateNaissance { get; set; }
public bool ADomicile { get; set; }
public int SeDeplace { get; set; }
public string IdWallet { get; set; }
public string IdUserMango { get; set; }
public Nullable<System.DateTime> DateAjout { get; set; }
public string onesignal_id { get; set; }
public List<NoteItem> Notes { get; set; }
/**/
public double NoteGlobale { get; set; }
public bool Son { get; set; }
public bool Push { get; set; }
public string IdPhone { get; set; }
}
public class NoteItem
{
public int? IdClient { get; set; }
public string Commentaire { get; set; }
public string ImageUrl { get; set; }
public double Note { get; set; }
public DateTime? DateAjout { get; set; }
public int Valide { get; set; }
}
}
Any kind of welp would be appreciated.
Thank to anyone who will take the time to read/answer this post.