using System; using System.Collections.Generic; using System.Linq; using System.Web; using EnVisage.Models; using EnVisage.Code.Cache; using System.Data.Entity; namespace EnVisage.Code.BLL { public class RoleManager : ManagerBase { public RoleManager(EnVisageEntities dbContext) : base(dbContext) { } protected override AspNetRole InitInstance() { return new AspNetRole();// { Id = Guid.NewGuid().ToString() }; } protected override AspNetRole RetrieveReadOnlyById(Guid key) { return DataTable.AsNoTracking().FirstOrDefault(t => t.Id == key.ToString()); } public override System.Data.Entity.DbSet DataTable { get { return DbContext.AspNetRoles; } } public override AspNetRole Save(RoleModel model) { if (model == null) throw new ArgumentNullException("model"); new UsersCache().Invalidate(); #region Save Role data AspNetRole dbObj = null; //ENV-746 START //if (model.Id != Guid.Empty) if (!model.isNew) //ENV-746 END dbObj = DbContext.AspNetRoles.Find(model.Id.ToString()); if (dbObj == null) { //ENV-746 START Guid g = Guid.NewGuid(); dbObj = new AspNetRole {Id = g.ToString() }; model.setIDForNewModel(g); //ENV-746 END } model.CopyTo(dbObj); //ENV-746 START if (model.isNew) //if (model.Id == Guid.Empty) //ENV-746 END DbContext.AspNetRoles.Add(dbObj); else DbContext.Entry(dbObj).State = EntityState.Modified; #endregion return dbObj; } } }