public async Task <ResponseMessage> SaveMembershipAsync(CustomerMembership customerMembership) { ResponseMessage message = new ResponseMessage { IsSuccess = false }; customerMembership.CreatedOn = DateTime.Now; _context.CustomerMemberships.Add(customerMembership); await _context.SaveChangesAsync(); message.IsSuccess = true; message.Detail = PackingSlipConstants.MembershipCreationSuccessMessage; return(message); }
public async Task <ResponseMessage> SavePackingSlipAsync(PackingSlipHeader packingSlip) { ResponseMessage message = new ResponseMessage { IsSuccess = false }; int maxNumber = 0; try { using (IDbContextTransaction transaction = _context.Database.BeginTransaction()) { if (_context.PackingSlipHeaders.Any()) { maxNumber = _context.PackingSlipHeaders.Max(s => s.Id); } packingSlip.PackingSlipNumber = $"PS-{maxNumber}"; _context.PackingSlipHeaders.Add(packingSlip); await _context.SaveChangesAsync(); int packingId = packingSlip.Id; foreach (var item in packingSlip.PackingSlipItems.ToList()) { var product = _context.Products.FirstOrDefault(x => x.Name == item.Name); _context.PackingSlipItems.Add(new PackingSlipItem { Amount = (item.IsFreeItem.HasValue && item.IsFreeItem.Value) ? 0 : item.Quantity * product.Rate, Name = item.Name, PackingSlipId = packingId, Quantity = item.Quantity, ProductId = product.Id, }); } await _context.SaveChangesAsync(); await transaction.CommitAsync(); message.IsSuccess = true; message.Detail = packingSlip.PackingSlipNumber; } } catch (Exception ex) { } return(message); }
public async Task <ResponseMessage> AddAgentCommission(PackingSlipHeader packingSlipHeader, decimal amount) { ResponseMessage message = new ResponseMessage { IsSuccess = false }; var commission = new AgentCommission { AgentName = packingSlipHeader.AgentName, Amount = amount, PackingSlipId = packingSlipHeader.Id }; _context.AgentCommissions.Add(commission); await _context.SaveChangesAsync(); message.IsSuccess = true; return(message); }