public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService , IAppRoleService appRoleService) { //Rol varsa eklemicem yoksa eklicem var adminRole = await appRoleService.FindByNameAsync(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByNameAsync(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } //admin kullanıcı eklmedim. var adminUser = await appUserService.FindByUserNameAsync("ADMIN"); if (adminUser == null) { await appUserService.Add(new AppUser { UserName = "******", Password = "******" }); } //appuserrole tablosuna bu ilişkiyi eklemem lazım var role = await appRoleService.FindByNameAsync(RoleInfo.Admin); var admin = await appUserService.FindByUserNameAsync("ADMIN"); //daha önce eklenmiş mi var allUSerRole = await appUserRoleService.GetAll(); int kontrol = allUSerRole.Where(x => x.AppRoleId == role.Id && x.AppUserId == admin.Id).Count(); if (kontrol == 0) { await appUserRoleService.Add(new AppUserRole { AppRoleId = role.Id, AppUserId = admin.Id }); } }
public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserName("veysel"); if (adminUser == null) { await appUserService.Add(new AppUser() { FullName = "ahmet veysel bozoğlu", Password = "******", UserName = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var admin = await appUserService.FindByUserName("veysel"); await appUserRoleService.Add(new AppUserRole { AppUserId = admin.Id, AppRoleId = role.Id }); } }
public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { //ilgili rol varmı? var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserName("sametirkoren"); if (adminUser == null) { await appUserService.Add(new AppUser { FullName = "Samet İrkören", UserName = "******", Password = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var admin = await appUserService.FindByUserName("sametirkoren"); await appUserRoleService.Add(new AppUserRole { AppUserId = admin.Id, AppRoleId = role.Id }); } }
public static async Task Seed(IAppUserService appUserService, IAppRoleService appRoleService, IAppUserRoleService appUserRoleService) { //have a role var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserName("enesb"); if (adminUser == null) { await appUserService.Add(new AppUser { UserName = "******", FullName = "enes baysal", Password = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var admin = await appUserService.FindByUserName("enesb"); await appUserRoleService.Add(new AppUserRole { AppRoleId = role.Id, AppUserId = admin.Id }); } }
public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminUser = await appUserService.FindByUserName("savas.ev"); if (adminUser == null) { await appUserService.Add(new AppUser { FullName = "Savaş Ev", UserName = "******", Password = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var user = await appUserService.FindByUserName("savas.ev"); await appUserRoleService.Add(new AppUserRole { AppUserId = user.Id, AppRoleId = role.Id }); } }
public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService) { var adminRole = await appRoleService.FindByName(RoleInfo.Admin); if (adminRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Admin }); } var memberRole = await appRoleService.FindByName(RoleInfo.Member); if (memberRole == null) { await appRoleService.Add(new AppRole { Name = RoleInfo.Member }); } var adminnUser = await appUserService.FindByUserName("sercan"); if (adminnUser == null) { await appUserService.Add(new AppUser { FullName = "sercan fırtına", UserName = "******", Password = "******" }); var role = await appRoleService.FindByName(RoleInfo.Admin); var admin = await appUserService.FindByUserName("sercan"); await appUserRoleService.Add(new AppUserRole { AppUserId = admin.Id, AppRoleId = role.Id }); } }
public HttpResponseMessage Add(HttpRequestMessage request, ApplicationRoleViewModel appRoleVm) { return(CreateHttpResponse(request, () => { if (ModelState.IsValid) { HttpResponseMessage response = null; var newRole = new AppRole(); newRole.UpdateRole(appRoleVm); newRole.Id = Guid.NewGuid().ToString();//sinh ngẫu nhiên id _appRoleService.Add(newRole); _appRoleService.Save(); var modelVm = Mapper.Map <AppRole, ApplicationRoleViewModel>(newRole); response = request.CreateResponse(HttpStatusCode.OK, modelVm); return response; } else { return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } })); }
public HttpResponseMessage Create(HttpRequestMessage request, AppRoleViewModel appRoleViewModel) { if (ModelState.IsValid) { var newAppRole = new AppRole(); newAppRole.UpdateAppRole(appRoleViewModel); try { _appRoleService.Add(newAppRole); _appRoleService.Save(); return(request.CreateResponse(HttpStatusCode.OK, appRoleViewModel)); } catch (NameDuplicatedException dex) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message)); } } else { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }