public async Task <CustomerDTO> CustomerEntry(CustomerDTO customerDTO) { var dataObejct = customerDTO as CustomerDTO; await _sqlServerContext.AddAsync(customerDTO); await _sqlServerContext.SaveChangesAsync(); return(customerDTO); }
public async Task <EmployeeDTO> EmployeeEntry(EmployeeDTO employeeDTO) { var dataObject = employeeDTO as Employee; await _sqlServerContext.AddAsync <Employee>(dataObject); await _sqlServerContext.SaveChangesAsync(); return(employeeDTO); }
public async Task <LocationDTO> LocationEntryUpdate(LocationDTO locationDTO) { var dataObject = locationDTO as Location; if (locationDTO.LocationId == 0) { await _sqlServerContext.AddAsync <Location>(dataObject); } else { _sqlServerContext.Update <Location>(dataObject); } await _sqlServerContext.SaveChangesAsync(); return(locationDTO); }
public async Task <ProductDTO> ProductEntryUpdate(ProductDTO productDTO) { var dataObject = productDTO as Product; if (productDTO.ProductId == 0) { await _sqlServerContext.AddAsync <Product>(dataObject); } else { _sqlServerContext.Update <Product>(dataObject); } await _sqlServerContext.SaveChangesAsync(); return(productDTO); }
//order place public async Task <OrderDTO> OrderEntry(OrderDTO orderDTO) { try { using (var transaction = await _sqlServerContext.Database.BeginTransactionAsync()) { try { orderDTO.OrderItemDTO = orderDTO.OrderItemDTO.Select(v => { v.TotalPrice = v.ProductQuantity * v.SellUnitPrice; return(v); }).ToList(); orderDTO.Price = orderDTO.OrderItemDTO.Sum(x => x.TotalPrice); orderDTO.OrderTotalCostAmount = orderDTO.OrderItemDTO.Sum(c => ((decimal)c.TotalPrice * (decimal)c.ProductCostPercentage) / 100); orderDTO.CompanyAmount = orderDTO.OrderItemDTO.Sum(c => ((decimal)c.TotalPrice * (decimal)c.CompanyPercentage) / 100); orderDTO.CustomerAmount = orderDTO.OrderItemDTO.Sum(c => ((decimal)c.TotalPrice * (decimal)c.CustomerPercentage) / 100); var dataObject = orderDTO as ResturantOrder; await _sqlServerContext.AddAsync <ResturantOrder>(dataObject); await _sqlServerContext.SaveChangesAsync(); orderDTO.OrderItemDTO = orderDTO.OrderItemDTO.Select(c => { c.OrderId = orderDTO.OrderId; return(c); }).ToList(); await OrderItemEntry(orderDTO.OrderItemDTO); await _sqlServerContext.SaveChangesAsync(); await transaction.CommitAsync(); return(orderDTO); } catch (Exception exp) { orderDTO = null; await transaction.RollbackAsync(); return(null); } } } catch (Exception exp) { throw exp; } }