//=====================================================GETS ABOVE===================================================== #region Save static public async Task <string> Save(EDeliveryOrder eOrder) { try { eOrder.modificationDateUTC = DateTime.UtcNow; using var context = new SMySQLContext(); if (string.IsNullOrEmpty(eOrder.id)) { eOrder.id = Guid.NewGuid().ToString(); eOrder.creationDateUTC = eOrder.modificationDateUTC = DateTime.UtcNow; var e = await context.DeliveryOrders.AddAsync(eOrder); await context.SaveChangesAsync(); return(e.Entity.id); } else { var e = context.DeliveryOrders.Update(eOrder); await context.SaveChangesAsync(); return(e.Entity.id); } } catch (DbUpdateException e) { Console.WriteLine(e.ToString()); throw; } }
static public bool ConfirmOrder(EDeliveryConfirmOrder eDeliveryConfirmOrder) { try { using var context = new SMySQLContext(); EDeliveryOrder e = new EDeliveryOrder(); e.companyID = eDeliveryConfirmOrder.companyID; e.visualID = GetNextVisualID(e.companyID); e.entityID = eDeliveryConfirmOrder.userID; e.paymentMethodType = eDeliveryConfirmOrder.paymentMethodType; e.total = eDeliveryConfirmOrder.total; e.creationDateUTC = e.modificationDateUTC = DateTime.UtcNow; if (eDeliveryConfirmOrder.creationDateLocal == null) { e.creationDateLocal = DateTime.UtcNow; } else { e.creationDateLocal = eDeliveryConfirmOrder.creationDateLocal; } e.notes = eDeliveryConfirmOrder.comments; e.status = DeliveryStatus.PendingApproval; e.content = JsonConvert.SerializeObject(eDeliveryConfirmOrder.productList); e.changeFor = eDeliveryConfirmOrder.changeFor; var result = context.DeliveryOrders.Add(e); context.SaveChanges(); return(true); } catch (Exception e) { SLogger.LogError(e); } return(false); }
static public EDeliveryOrder GetByID(string id) { using var context = new SMySQLContext(); EDeliveryOrder eDeliveryOrder = context.DeliveryOrders.SingleOrDefault(x => x.id == id); if (eDeliveryOrder != null) { eDeliveryOrder.statusName = GetStatusName(eDeliveryOrder.status); } return(eDeliveryOrder); }
static public async Task <bool> Remove(string id) { using var context = new SMySQLContext(); EDeliveryOrder eOrder = context.DeliveryOrders.SingleOrDefault(x => x.id == id); if (eOrder == null) { return(false); } context.Remove(eOrder); await context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Save([FromBody] EDeliveryOrder eOrder) { var result = await SDeliveryOrders.Save(eOrder); return(Ok(result)); }