/// <summary> /// Сохраняет, обновляет <see cref="AccessRole"/> роль пользователя в БД, /// не снимает уже обновленную роль с пользователя /// </summary> /// <returns></returns> public ServiceResponce SaveRole(AccessRoleModel model) { AccessRoles toSave = null; if (model.Id == 0) { toSave = new AccessRoles(); } else { toSave = _accessRep.GetOneById(model.Id); if (toSave == null) { return(ServiceResponce .FromFailed() .Add("error", "Role can't be update, because it does not exist")); } } toSave = AccessRoleModelHelper.UpdateAccessRole(toSave, model); if (toSave == null) { return(ServiceResponce .FromFailed() .Add("error", "Error while parsing AccessRoles in specified role")); } _accessRep.Save(toSave); return(ServiceResponce .FromSuccess() .Result(model.Id == 0 ? "Created" : "Updated")); }
public IHttpActionResult Test() { string temp = GlobalConfiguration.Configuration.DependencyResolver.ToString(); UserInfo ui = new UserInfo() { Company = "Home" }; AccessRoles ar = new AccessRoles() { Name = "ar1" }; User user = new User { UserName = "******", AccessRoles = ar, UserInfo = ui }; UserRep.Save(user); user.UserInfo.Name = "Василий"; UserRep.Save(user); AccessRoles ar2 = new AccessRoles() { Name = "ar2" }; user.AccessRoles = ar2; UserRep.Save(user); UserRep.Delete(user); return(Ok()); }
public ActionResult DeleteConfirmed(int id) { AccessRoles accessRoles = db.AccessRoles.Find(id); db.AccessRoles.Remove(accessRoles); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Обновляет <see cref="AccessRole"/> <paramref name="toUpdate"/> из <paramref name="model"/>; /// Если во время обновления произошло исключение возвращает <c>null</c> /// </summary> /// <param name="toUpdate"></param> /// <param name="model"></param> /// <returns></returns> public static AccessRoles UpdateAccessRole(AccessRoles toUpdate, AccessRoleModel model) { try { toUpdate.Name = model.Name; toUpdate.Desciption = model.Desciption; toUpdate.Role = (AccessRoleType)Enum.Parse(typeof(AccessRoleType), model.Roles, true); return(toUpdate); } catch (Exception) { return(null); } }
// GET: AccessRoles/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AccessRoles accessRoles = db.AccessRoles.Find(id); if (accessRoles == null) { return(HttpNotFound()); } return(View(accessRoles)); }
/// <summary> /// Получает <see cref="AccessRoleModel"/> из <paramref name="role"/> /// </summary> /// <param name="role"></param> /// <returns></returns> public static AccessRoleModel GetAccessRoleModel(AccessRoles role) { if (role == null) { return(null); } return(new AccessRoleModel() { Id = role.Id, Name = role.Name, Desciption = role.Desciption, Roles = role.Role.ToString() }); }
public ActionResult Edit([Bind(Include = "ID,name,createdate,creator,modifieddate,modifier")] AccessRoles accessRoles) { if (ModelState.IsValid) { string currentuser = !string.IsNullOrEmpty(User?.Identity?.Name) ? User.Identity.Name.ToUpper() : "Anonymous"; currentuser = currentuser.Substring(currentuser.IndexOf('\\') + 1).Replace("\\", "").ToUpper(); accessRoles.modifier = currentuser; accessRoles.modifieddate = DateTime.UtcNow; db.Entry(accessRoles).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(accessRoles)); }
public ActionResult Create([Bind(Include = "name")] AccessRoles accessRoles) { if (accessRoles != null && accessRoles.name != null) { string currentuser = !string.IsNullOrEmpty(User?.Identity?.Name) ? User.Identity.Name.ToUpper() : "Anonymous"; currentuser = currentuser.Substring(currentuser.IndexOf('\\') + 1).Replace("\\", "").ToUpper(); accessRoles.creator = currentuser; accessRoles.createdate = DateTime.UtcNow; db.AccessRoles.Add(accessRoles); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(accessRoles)); }
public static bool CanRead(this AccessRoles roles) { return(roles != AccessRoles.None); }
/// <summary> /// Получает роль с <paramref name="id"/> /// и оборачивает ее в <see cref="AccessRoleModel"/> /// </summary> /// <param name="id"></param> /// <returns></returns> public AccessRoleModel GetRole(int id) { AccessRoles role = _accessRep.GetOneById(id); return(AccessRoleModelHelper.GetAccessRoleModel(role)); }
void BaseDb(GetticketDBContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. AccessRoles admin = new AccessRoles() { Name = "Admin", Desciption = "Full access", Id = 1, Role = Enums.AccessRoleType.Admin }; context.AccessRoles.AddOrUpdate(ar => ar.Id, admin); context.AccessRoles.AddOrUpdate(ar => ar.Id, new AccessRoles { Desciption = "Default role", Id = 2, Name = "User", Role = AccessRoleType.User }); context.SaveChanges(); // md5 are: // teest: ccfcb5961cb870496289a62c2a6f728c78feb49f448972daf0a6f098a903be08 // deleted: 1185f37d33b0f89e331f101a51bb8e51165c7efda15950b86a3ebcbb363f898e // admin: 8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918 User user1 = new User() { Id = 1, UserName = "******", UserPhone = "+79063332211", Password = "******", AccessRoleId = 1, UserStatuses = new UserStatuses() { Name = "seed", Description = "", Status = UserStatusType.System }, UserInfo = new UserInfo() { Id = 1, Name = "Тест", LastName = "Админ" } }; User user2 = new User() { Id = 2, UserName = "******", UserPhone = "+79153332211", Password = "******", AccessRoleId = 1, UserStatuses = new UserStatuses() { Name = "seed", Description = "deleted", Status = UserStatusType.MarkDeleted }, UserInfo = new UserInfo() { Id = 2, Name = "deleted", LastName = "Админ" } }; User user3 = new User() { Id = 3, UserName = "******", UserPhone = "+79153332258", Password = "******", AccessRoleId = 1, UserStatuses = new UserStatuses() { Name = "seed", Description = "admin", Status = UserStatusType.System }, UserInfo = new UserInfo() { Id = 3, Name = "gtadmin", LastName = "Админ" } }; var user4 = new User() { Id = 4, UserName = "******", UserPhone = "+79788701877", Password = "******", AccessRoleId = 1, UserStatuses = new UserStatuses() { Name = "seed", Description = "", Status = UserStatusType.System }, UserInfo = new UserInfo() { Id = 4, Name = "admin", LastName = "Админ" } }; context.Users.AddOrUpdate(u => u.Id, user1); context.Users.AddOrUpdate(u => u.Id, user2); context.Users.AddOrUpdate(u => u.Id, user3); context.Users.AddOrUpdate(u => u.Id, user4); //context.UserPageCategories.AddOrUpdate(o => o.Id, new UserPageCategory { Id = 1, Name = "Не указано" }); //context.SaveChanges(); var pers1 = new Person { Id = 1, Name = "Светлана", LastName = "Абакачева", Sex = Sex.Female, Bithday = new DateTime(1990, 5, 16), id_Bithplace = 2295 }; var pers2 = new Person { Id = 2, Name = "Джастин", LastName = "Тимберлейк", NameLatin = "Justin", LastNameLatin = "Timberlake", Sex = Sex.Male, Bithday = new DateTime(1985, 11, 5), id_Bithplace = 177329 }; var pers3 = new Person { Id = 3, Name = "Анна", LastName = "Сидорова", Patronymic = "Владимировна", NameLatin = "Anna", LastNameLatin = "Sidorova", PatronymicLatin = "Vladimirova", Sex = Sex.Female, Bithday = new DateTime(1995, 3, 14), id_Bithplace = 2295 }; var pers4 = new Person { Id = 4, Name = "Вероника", LastName = "Абасова", Sex = Sex.Female, Bithday = new DateTime(1989, 8, 12), id_Bithplace = 2296 }; var pers5 = new Person { Id = 5, Name = "Алена", LastName = "Бабенко", Sex = Sex.Female, Bithday = new DateTime(1986, 7, 10), id_Bithplace = 2296 }; var pers6 = new Person { Id = 5, Name = "Алена", LastName = "Бабенко", Sex = Sex.Female, Bithday = new DateTime(1986, 7, 10), id_Bithplace = 5 }; context.Person.AddOrUpdate(o => o.Id, pers1); context.Person.AddOrUpdate(o => o.Id, pers2); context.Person.AddOrUpdate(o => o.Id, pers3); context.Person.AddOrUpdate(o => o.Id, pers4); context.Person.AddOrUpdate(o => o.Id, pers5); context.EventCategories.AddOrUpdate(o => o.Id, new EventCategory { Id = 1, Name = "Спорт" }); context.EventCategories.AddOrUpdate(o => o.Id, new EventCategory { Id = 2, Name = "Театр" }); context.EventCategories.AddOrUpdate(o => o.Id, new EventCategory { Id = 3, Name = "Музыка" }); context.SaveChanges(); context.EventCategories.AddOrUpdate(o => o.Id, new EventCategory { Id = 4, Name = "Бокс", IdParent = 1 }); context.EventCategories.AddOrUpdate(o => o.Id, new EventCategory { Id = 5, Name = "Фигурное катание", IdParent = 1 }); context.EventCategories.AddOrUpdate(o => o.Id, new EventCategory { Id = 6, Name = "Концерт", IdParent = 3 }); context.EventCategories.AddOrUpdate(o => o.Id, new EventCategory { Id = 7, Name = "Спектакль", IdParent = 2 }); context.EventCategories.AddOrUpdate(o => o.Id, new EventCategory { Id = 8, Name = "Балет", IdParent = 2 }); context.EventCategories.AddOrUpdate(o => o.Id, new EventCategory { Id = 9, Name = "Концерт", IdParent = 2 }); context.SaveChanges(); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 1, Name = "Бокс", IdCategory = 4, AgeLimit = 16, IsReallyEvent = true, Description = "1/5 Бой за звание чемпиона мира по боксу в супертяжелом весе по версии WBA Лукас Браун..." }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 2, Name = "Фигурное катание", IdCategory = 5, AgeLimit = 4, Description = "3 Чемпионат мира по фигурному катанию" }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 3, Name = "Весёлые бабури", IdCategory = 6, AgeLimit = 14, IsReallyEvent = true, Description = "1/2 Петр Налич и биг-бенд \"Песни Утесова и не только...\"" }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 4, Name = "Джаз", IdCategory = 6, AgeLimit = 14, IsReallyEvent = true, Description = "8 А.Кролл, Л.Ролл, М. Волл День джаза в Доме музыки. \"Все цвета московского джаза\"" }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 5, Name = "Вишневый сад", IdCategory = 7, AgeLimit = 12 }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 6, Name = "Лебединое озеро", IdCategory = 8, AgeLimit = 10 }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 7, Name = "Современник", IdCategory = 2, AgeLimit = 12 }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 8, Name = "Justified", IdCategory = 6, AgeLimit = 14, IsReallyEvent = true }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 9, Name = "Бокс", IdCategory = 4, AgeLimit = 16, Description = "Чемпиона мира по боксу в супертяжелом весе по версии WBA" }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 10, Name = "New Year. Titanic. Live.", Description = "Новогодний симфонический киноконцерт инициативы Большого театра ", IdCategory = 9, AgeLimit = 12 }); context.SaveChanges(); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 11, IsReallyEvent = true, Name = "Классическая-сцена", IdCategory = 9, AgeLimit = 12, ParentId = 10 }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 12, IsReallyEvent = true, Name = "Рок-сцена", IdCategory = 9, AgeLimit = 12, ParentId = 10 }); context.Events.AddOrUpdate(o => o.Id, new Event { Id = 13, IsReallyEvent = true, Name = "Chris LeDoux и легенды кантри", IdCategory = 9, AgeLimit = 12, ParentId = 10 }); context.SaveChanges(); context.ConnectionTypes.AddOrUpdate(o => o.Id, new ConnectionType { Id = 1, Name = "Персона" }); context.ConnectionTypes.AddOrUpdate(o => o.Id, new ConnectionType { Id = 2, Name = "Мероприятие" }); context.ConnectionTypes.AddOrUpdate(o => o.Id, new ConnectionType { Id = 3, Name = "Событие" }); context.SaveChanges(); context.MediaTypes.AddOrUpdate(o => o.Id, new MediaType { Id = 1, Name = "Видео" }); context.MediaTypes.AddOrUpdate(o => o.Id, new MediaType { Id = 2, Name = "Фото" }); context.SaveChanges(); }