public void AddUpdateUserSite(UserSiteCreateModel model) { DeleteSiteForUser(model.UserId); List <UserSite> urList = new List <UserSite>(); using (var db = new PCVEntities()) { if (model.SiteId.IsNotBlank()) { foreach (var item in model.SiteId) { UserSite oneRoleMenu = new UserSite(); oneRoleMenu.UserId = model.UserId; oneRoleMenu.SiteId = item; oneRoleMenu.CreatedDate = DateTime.Now; oneRoleMenu.CreatedBy = MySession.Current.UserName; if (model.IsDefault == item.To <string>()) { oneRoleMenu.IsDefaultSite = true; } else { oneRoleMenu.IsDefaultSite = false; } urList.Add(oneRoleMenu); } db.UserSite.AddRange(urList); db.SaveChanges(); } } }
public JsonResult AssignUserSites(UserSiteCreateModel model) { if (model.IsNotBlank()) { _unitofwork.HomeRepo.AddUpdateUserSite(model); return(Json(new { success = true, message = "Assigned successfully !!" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "some error occured !!" }, JsonRequestBehavior.AllowGet)); }