public async Task <ActionResult> Create([FromBody] SaveOrderRequest entity) { try { var order = mapper.Map <Order>(entity); // Deduct quantities from inventory await inventoryService.ProcessAdjustments(order.LineItems, AdjustmentType.Deduct, Constants.AdjustmentRemarks.OrderCreated, QuantityType.Quantity); await context.Orders.AddAsync(order); await context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created)); } catch (QuantityBelowZeroException ex) { logger.LogError(ex.Message); ModelState.AddModelError(Constants.ErrorMessage, ex.Message); return(BadRequest(ModelState)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> Create([FromBody] SaveCreditMemoRequest entity) { try { var creditMemo = mapper.Map <CreditMemo>(entity); await context.CreditMemos.AddAsync(creditMemo); // Adjust the inventory quantities for items returned var itemsToBeReturned = creditMemo.LineItems.Where(a => a.ReturnedToInventory); await inventoryService.ProcessAdjustments(itemsToBeReturned, AdjustmentType.Add, Constants.AdjustmentRemarks.CreditMemoCreated, QuantityType.Both); // Update the order line item for quantity returned await orderService.ProcessReturns(creditMemo.LineItems, AdjustmentType.Add); await context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created)); } catch (QuantityReturnedException qEx) { logger.LogError(qEx.Message); ModelState.AddModelError(Constants.ErrorMessage, qEx.Message); return(BadRequest(ModelState)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> Create([FromBody] SaveItemRequest entity) { try { var item = mapper.Map <Item>(entity); context.ItemHistories.Add(new ItemHistory { Item = item, Date = DateTime.Now, Quantity = entity.Quantity, Remarks = Constants.AdjustmentRemarks.InitialQuantity }); await context.Items.AddAsync(item); await context.SaveChangesAsync(); return(CreatedAtRoute(nameof(GetItemById), new { id = item.Id }, entity)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> Create([FromBody] SaveDeliveryRequest entity) { try { RemoveZeroLineItems(entity); var delivery = mapper.Map <Delivery>(entity); await context.Deliveries.AddAsync(delivery); // Update the order line item for quantity returned await orderService.ProcessDeliveries(delivery.LineItems, AdjustmentType.Add); await context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created)); } catch (QuantityDeliveredException dEx) { logger.LogError(dEx.Message); ModelState.AddModelError(Constants.ErrorMessage, dEx.Message); return(BadRequest(ModelState)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult <SaveProvinceRequest> > Create([FromBody] SaveProvinceRequest entity) { try { var province = mapper.Map <Province>(entity); await context.Provinces.AddAsync(province); await context.SaveChangesAsync(); return(CreatedAtRoute(nameof(GetProvinceById), new { id = province.Id }, entity)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult <SaveCustomerRequest> > Create([FromBody] SaveCustomerRequest entity) { try { var customer = mapper.Map <Customer>(entity); await context.Customers.AddAsync(customer); await context.SaveChangesAsync(); return(CreatedAtRoute(nameof(GetCustomerById), new { id = customer.Id }, entity)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult <SaveCategoryRequest> > Create([FromBody] SaveCategoryRequest entity) { try { var category = mapper.Map <Category>(entity); await context.Categories.AddAsync(category); await context.SaveChangesAsync(); return(CreatedAtRoute(nameof(GetCategoryById), new { id = category.Id }, entity)); } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> Create([FromBody] SaveCashVoucherRequest entity) { try { var cashVoucher = mapper.Map <CashVoucher>(entity); await context.CashVouchers.AddAsync(cashVoucher); await context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> Create([FromBody] SaveSalesQuoteRequest entity) { try { var salesQuote = mapper.Map <SalesQuote>(entity); await context.SalesQuotes.AddAsync(salesQuote); await context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult <SaveUserRequest> > Create([FromBody] SaveUserRequest entity) { try { var user = mapper.Map <ApplicationUser>(entity); user.PasswordHash = passwordHasher.HashPassword(user, entity.Password); await context.Users.AddAsync(user); await context.SaveChangesAsync(); return(CreatedAtRoute(nameof(GetUserById), new { id = user.Id }, entity)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <ActionResult> Create([FromBody] SaveInvoiceRequest entity) { try { var invoice = mapper.Map <Invoice>(entity); await orderService.ProcessInvoice(invoice.LineItems, true); var orderIds = invoice.LineItems.Where(a => a.OrderId != null).Select(a => a.OrderId.Value); var orderLineItems = context.OrderLineItems .Where(a => orderIds.Contains(a.OrderId)); await inventoryService.ProcessAdjustments(orderLineItems, AdjustmentType.Deduct, Constants.AdjustmentRemarks.InvoiceCreated, QuantityType.StockQuantity); await context.Invoices.AddAsync(invoice); await context.SaveChangesAsync(); return(StatusCode(StatusCodes.Status201Created)); } catch (Exception e) { logger.LogError(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }