public async Task <IActionResult> PutApplicationSetting([FromRoute] int id, [FromBody] ApplicationSetting applicationSetting) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != applicationSetting.Id) { return(BadRequest()); } applicationSetting.UpdatedAt = DateTimeOffset.Now; _context.Entry(applicationSetting).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApplicationSettingExists(id)) { return(NotFound()); } else { throw; } } return(Ok(_context.ApplicationSettings.Find(id))); }
public async Task <IActionResult> PutInvoice([FromRoute] int id, [FromBody] Invoice invoice) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != invoice.Id) { return(BadRequest()); } _context.Entry(invoice).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InvoiceExists(id)) { return(NotFound()); } else { throw; } } return(Ok(_context.Invoices.Find(id))); }
public async Task <IActionResult> PutOrderType([FromRoute] int id, [FromBody] OrderType orderType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != orderType.Id) { return(BadRequest()); } orderType.UpdatedAt = DateTimeOffset.Now; _context.Entry(orderType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderTypeExists(id)) { return(NotFound()); } else { throw; } } return(Ok(_context.OrderTypes.Find(id))); }
public async Task <IActionResult> PutPaymentReceipt([FromRoute] int id, [FromBody] PaymentReceipt paymentReceipt) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != paymentReceipt.Id) { return(BadRequest()); } _context.Entry(paymentReceipt).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PaymentReceiptExists(id)) { return(NotFound()); } else { throw; } } return(Ok(_context.PaymentReceipts.Find(id))); }
public async Task <IActionResult> PostDispatch([FromRoute] int pickingId, [FromBody] List <string> orderNumbers) { if (orderNumbers.Any()) { // Get list of orders by order numbers List <Models.Order> orders = await _context .Orders .Where(x => orderNumbers.Contains(x.OrderNumber)) .Where(x => x.ConsolidatedOrderId == null) .ToListAsync(); // Verify whether any order was found by order number if (orders.Any()) { // Get current date/time DateTimeOffset now = DateTimeOffset.Now; // Create new empty consolidated order object ConsolidatedOrder consolidatedOrder = new ConsolidatedOrder(); consolidatedOrder.RouteCode = orders.First().DeliveryRoute; consolidatedOrder.PickingId = pickingId; consolidatedOrder.OrderStatus = 0; // Assigned consolidatedOrder.CreatedAt = now; consolidatedOrder.UpdatedAt = now; // Add consolidated order to database context _context.ConsolidatedOrders.Add(consolidatedOrder); // Save new consolidated order await _context.SaveChangesAsync(); // Iterate through all orders found foreach (var order in orders) { // Assign consolidated order id to order order.ConsolidatedOrderId = consolidatedOrder.Id; // Add modify status to entity _context.Entry(order).State = EntityState.Modified; // Save changes await _context.SaveChangesAsync(); } // Return new consolidated order created return(Ok(consolidatedOrder)); } else { return(NotFound(new { error = "Non order found into the list of order number given" })); } } else { return(BadRequest(new { error = "Order numbers can not be empty" })); } }
public async Task <IActionResult> PutSalesChannel([FromRoute] int id, [FromBody] SalesChannel salesChannel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != salesChannel.Id) { return(BadRequest()); } salesChannel.UpdatedAt = DateTimeOffset.Now; _context.Entry(salesChannel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SalesChannelExists(id)) { return(NotFound()); } else { throw; } } return(Ok(_context.SalesChannels.Find(id))); }
public async Task <IActionResult> PutExchangeRateByCustomer([FromRoute] int id, [FromBody] ExchangeRateByCustomer exchangeRateByCustomer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != exchangeRateByCustomer.Id) { return(BadRequest()); } _context.Entry(exchangeRateByCustomer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExchangeRateByCustomerExists(id)) { return(NotFound()); } else { throw; } } return(Ok(_context.ExchangeRateByCustomers.Find(id))); }
public async Task <IActionResult> PutCostCenterByItemFamily([FromRoute] int id, [FromBody] CostCenterByItemFamily costCenterByItemFamily) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != costCenterByItemFamily.Id) { return(BadRequest()); } _context.Entry(costCenterByItemFamily).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CostCenterByItemFamilyExists(id)) { return(NotFound()); } else { throw; } } return(Ok(_context.CostCenterByItemFamilies.Find(id))); }
public async Task <IActionResult> PutRouteEventItem([FromRoute] int id, [FromBody] RouteEventItem routeEventItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != routeEventItem.Id) { return(BadRequest()); } routeEventItem.UpdatedAt = DateTimeOffset.Now; _context.Entry(routeEventItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RouteEventItemExists(id)) { return(NotFound()); } else { throw; } } return(Ok(_context.RouteEventItems.Find(id))); }
public async Task <IActionResult> PutBonusStatusLog([FromRoute] int id, [FromBody] BonusStatusLog bonusStatusLog) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bonusStatusLog.Id) { return(BadRequest()); } _context.Entry(bonusStatusLog).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BonusStatusLogExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDevice([FromRoute] int id, [FromBody] Device device) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != device.Id) { return(BadRequest()); } var _device = await _context.Devices.FindAsync(id); device.Status = _device.Status; device.CreatedAt = _device.CreatedAt; device.UpdatedAt = DateTimeOffset.Now; _context.Entry(_device).State = EntityState.Detached; _context.Entry(device).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeviceExists(id)) { return(NotFound()); } else { throw; } } return(Ok(_context.Devices.Find(id))); }
public async Task <IActionResult> AcceptInvitation([FromBody] Models.User _user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var users = await _context .Users .Include(x => x.Info) .ThenInclude(x => x.Phones) .Include(x => x.Setting) .Include(x => x.Roles) .ThenInclude(x => x.Role) .ThenInclude(x => x.Modules) .ThenInclude(x => x.Module) .ThenInclude(x => x.Children) .Include(x => x.Devices) .ThenInclude(x => x.Device) .Where(x => x.Username == _user.Username) .ToListAsync(); if (users.Any()) { if (string.IsNullOrEmpty(_user.TypedPassword)) { return(StatusCode(403, "Password can not be empty")); } var user = users.First(); Helpers.User.CreatePassword(_user.TypedPassword, out byte[] hashPasswordSalt, out byte[] hashPassword); user.PasswordSalt = hashPasswordSalt; user.Password = hashPassword; user.ResetPasswordToken = null; user.ResetPasswordSentAt = DateTimeOffset.MinValue; user.ResetPasswordExpiredAt = DateTimeOffset.MinValue; user.Status = Status.Active; user.UpdatedAt = DateTimeOffset.Now; // Update user setting with last consecutive invoices UpdateUserSettingWithLastConsecutiveNumbers(user); // Update user roles with their synchronization steps UpdateUserRolesWithSynchronizationSteps(user); _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(CreatedAtAction("GetUser", new { username = user.Username }, user)); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Id)) { return(NotFound()); } else { throw; } } } else { return(NotFound("Username can not be found")); } }