public async Task <IResponse <ProductCategory> > AddAsync(ProductCategory model) { await _productCategoryRepo.AddAsync(model); var saveResult = await _appUow.ElkSaveChangesAsync(); return(new Response <ProductCategory> { Result = model, IsSuccessful = saveResult.IsSuccessful, Message = saveResult.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 }); }
public async Task <IResponse <(Order Order, bool IsChanged)> > Add(OrderDTO model) { var chkResult = await _productSrv.CheckChanges(model.Items); var productId = chkResult.Items.Where(x => x.Count != 0).First().Id; var store = await _appUow.ProductRepo.FirstOrDefaultAsync(x => new { x.StoreId, x.Store.AddressId }, x => x.ProductId == productId); if (store == null) { return new Response <(Order, bool)> { Message = ServiceMessage.RecordNotExist } } ; var address = await _appUow.AddressRepo.FindAsync(store.AddressId); if (address == null) { await _appUow.AddressRepo.FindAsync(store.AddressId); } var getDeliveryCost = await _deliverySrv.GetDeliveryCost(model.DeliveryId, store.StoreId, new LocationDTO { Lat = model.Address.Lat, Lng = model.Address.Lng }); if (!getDeliveryCost.IsSuccessful) { return new Response <(Order, bool)> { Message = getDeliveryCost.Message } } ; var orderDetails = chkResult.Items.Where(x => x.Count != 0).Select(i => new OrderDetail { ProductId = i.Id, Count = i.Count, Price = i.Price, TotalPrice = i.RealPrice * i.Count, DiscountPrice = i.DiscountPrice, DiscountPercent = i.Discount }).ToList(); var order = new Order { StoreId = store.StoreId, TotalPrice = orderDetails.Sum(x => x.Price * x.Count), TotalPriceAfterDiscount = orderDetails.Sum(x => x.TotalPrice) + getDeliveryCost.Result, UserId = model.UserToken, DiscountPrice = orderDetails.Sum(x => x.DiscountPrice), OrderStatus = OrderStatus.WaitForPayment, DeliveryProviderId = model.DeliveryId, OrderComment = model.Description, UserComment = new UserComment { Reciever = model.Reciever, RecieverMobileNumber = model.RecieverMobileNumber }.SerializeToJson(), ToAddressId = model.Address.Id ?? 0, ToAddress = model.Address.Id == null ? new Address { UserId = model.UserToken, AddressType = AddressType.Home, Latitude = model.Address.Lat, Longitude = model.Address.Lng, AddressDetails = model.Address.Address } : null, FromAddressId = store.AddressId ?? 0, OrderDetails = orderDetails }; await _orderRepo.AddAsync(order); var addOrder = await _appUow.ElkSaveChangesAsync(); if (!addOrder.IsSuccessful) { return new Response <(Order, bool)> { Message = addOrder.Message } } ; return(new Response <(Order, bool)> { IsSuccessful = true, Result = (order, chkResult.Changed) }); }