public async Task <IResponse <ActionInRole> > AddAsync(ActionInRole model) { if (await _authUow.ActionInRoleRepo.AnyAsync(x => x.RoleId == model.RoleId && x.ActionId == model.ActionId)) { return new Response <ActionInRole> { Message = ServiceMessage.DuplicateRecord, IsSuccessful = false } } ; if (model.IsDefault) { var existActionInRole = await _authUow.ActionInRoleRepo.FirstOrDefaultAsync(conditions : x => x.RoleId == model.RoleId && x.IsDefault); if (existActionInRole.IsNotNull()) { existActionInRole.IsDefault = false; } } await _authUow.ActionInRoleRepo.AddAsync(model); var saveResult = await _authUow.ElkSaveChangesAsync(); return(new Response <ActionInRole> { Result = model, Message = saveResult.Message, IsSuccessful = saveResult.IsSuccessful, }); }
public async Task <IResponse <Action> > AddAsync(Action model) { await _authUow.ActionRepo.AddAsync(model); var saveResult = _authUow.ElkSaveChangesAsync(); return(new Response <Action> { Result = model, IsSuccessful = saveResult.Result.IsSuccessful, Message = saveResult.Result.Message }); }
public async Task <IResponse <UserInRole> > Add(UserInRole model) { if (await _userInRoleRepo.AnyAsync(x => x.UserId == model.UserId && x.RoleId == model.RoleId)) { return new Response <UserInRole> { Message = ServiceMessage.DuplicateRecord, IsSuccessful = false } } ; await _userInRoleRepo.AddAsync(model); var saveResult = await _authUow.ElkSaveChangesAsync(); return(new Response <UserInRole> { Result = model, Message = saveResult.Message, IsSuccessful = saveResult.IsSuccessful }); }
public async Task <IResponse <Domain.Store> > SignUp(StoreSignUpModel model) { using var tb = _appUow.Database.BeginTransaction(); var mobileNumber = long.Parse(model.MobileNumber); var user = await _appUow.UserRepo.FirstOrDefaultAsync(conditions : x => x.MobileNumber == mobileNumber, null); var store = await _storeRepo.FirstOrDefaultAsync(conditions : x => x.Username == model.Username, null); if (store != null) { return new Response <Domain.Store> { Message = ServiceMessage.DuplicateRecord } } ; var cdt = DateTime.Now; store = new Domain.Store { Username = model.Username, //FolowerCount = crawl.FolowerCount, //FolowingCount = crawl.FolowingCount, StoreType = StoreType.Instagram, StoreStatus = StoreStatus.Register, ProfilePictureUrl = null, //crawl.ProfilePictureUrl, LastCrawlTime = null, //crawl.LastCrawlDate, FullName = model.StoreName, //crawl.FullName, IsActive = true, User = user ?? new User { FullName = model.FullName, IsActive = true, MobileNumber = mobileNumber, LastLoginDateMi = cdt, LastLoginDateSh = PersianDateTime.Now.ToString(PersianDateTimeFormat.Date), InsertDateMi = cdt, Password = HashGenerator.Hash(mobileNumber.ToString()), NewPassword = HashGenerator.Hash(mobileNumber.ToString()), MustChangePassword = false, UserStatus = UserStatus.AddStore } }; await _storeRepo.AddAsync(store); var saveStore = await _appUow.ElkSaveChangesAsync(); if (!saveStore.IsSuccessful) { tb.Rollback(); return(new Response <Domain.Store> { Message = saveStore.Message }); } if (user == null) { await _authUow.UserInRoleRepo.AddAsync(new UserInRole { UserId = store.UserId, RoleId = model.StoreRoleId ?? 0 }); var saveUserInRole = await _authUow.ElkSaveChangesAsync(); if (!saveUserInRole.IsSuccessful) { tb.Rollback(); } else { tb.Commit(); } return(new Response <Domain.Store> { IsSuccessful = saveUserInRole.IsSuccessful, Result = store, Message = saveStore.Message }); } tb.Commit(); return(new Response <Domain.Store> { IsSuccessful = true, Result = store }); }