public async Task <IActionResult> PutNotificationItem(int id, NotificationItem notificationItem) { if (id != notificationItem.NotificationItemId) { return(BadRequest()); } _context.Entry(notificationItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NotificationItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutStatus(int id, Status status) { if (id != status.StatusId) { return(BadRequest()); } _context.Entry(status).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StatusExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSystemParam(int id, SystemParam systemParam) { if (id != systemParam.SystemParamId) { return(BadRequest()); } User modifiedBy = _context.Users.Find(systemParam.ModifiedBy_UserId); systemParam.ModifiedBy = modifiedBy; systemParam.ModifiedBy_UserId = modifiedBy.UserId; systemParam.ModifiedDate = DateTime.Now; _context.Entry(systemParam).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SystemParamExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UpdateUser(User newUser) { var user = _context.Users.Find(newUser.UserId); if (user == null) { return(NotFound()); } user.DisplayName = newUser.DisplayName; user.FirstName = newUser.FirstName; user.LastName = newUser.LastName; user.Email = newUser.Email; user.Password = newUser.Password; _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } return(NoContent()); }
public async Task <IActionResult> PutMessage(int id, Message message) { if (id != message.MessageId) { return(BadRequest()); } _context.Entry(message).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MessageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <bool> SaveOrderAsync(Order Order) { Order.Product = null; Order.Provider = null; Order.OrderId = 0; var p = await POSContext.Orders.AddAsync(Order); int result = await POSContext.SaveChangesAsync(); return(result > 0); }
public async Task <bool> SaveProductAsync(Product product) { product.Category = null; product.Provider = null; product.ProductId = 0; var p = await POScontext.Products.AddAsync(product); int result = await POScontext.SaveChangesAsync(); return(result > 0); }
public async Task <int> AddShopStatus(AddShopStatusRequest request) { var shopStatus = new ShopStatus { statusName = request.statusName, createUser = "******", //TODO: Get UserName Login createDate = DateTime.Now, updateDate = DateTime.Now, }; _context.ShopStatuses.Add(shopStatus); return(await _context.SaveChangesAsync()); }
public async Task <int> AddRegion(AddRegionRequest request) { var region = new POSSolution.Application.Models.Region { name = request.name, code = request.code, shop = request.shop, createUser = "******", //TODO: Get UserName Login createDate = DateTime.Now, updateDate = DateTime.Now }; _context.Regions.Add(region); return(await _context.SaveChangesAsync()); }
public async Task <bool> SaveCategoryAsync(Category product) { await POSContext.Categories.AddAsync(product); int result = await POSContext.SaveChangesAsync(); return(result > 0); }
public async Task <bool> SaveProviderAsync(Provider product) { await POSContext.Providers.AddAsync(product); int result = await POSContext.SaveChangesAsync(); return(result > 0); }
public async Task <int> AddShop(AddShopRequest request) { var shop = new POSSolution.Application.Models.Shop() { name = request.name, address = request.address, image = request.image, note = request.note, status = request.status, createUser = "******", //TODO: Get UserName Login createDate = DateTime.Now, updateDate = DateTime.Now }; _context.Shops.Add(shop); return(await _context.SaveChangesAsync()); }
public async Task <HttpResponseMessage> PostAsync([FromBody] Proforma proforma) { var transaccion = db.Database.BeginTransaction(); try { EncProforma Consulta = db.EncProforma.Where(a => a.NumProforma == proforma.encProforma.NumProforma).FirstOrDefault(); if (Consulta == null) { proforma.encProforma.FecFactura = DateTime.Now; db.EncProforma.Add(proforma.encProforma); await db.SaveChangesAsync(); foreach (var det in proforma.detProforma) { det.NumProforma = proforma.encProforma.NumProforma; det.Nompro = det.Nompro; //db.Productos.Where(a => a.Codpro == det.Codpro).Select(u => u.Nompro).FirstOrDefault(); db.DetProforma.Add(det); db.SaveChanges(); } transaccion.Commit(); resp = new { Success = true }; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { throw new Exception("Producto ya existe"); } } catch (Exception ex) { transaccion.Rollback(); // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public async Task <ActionResult <POSItems> > PostPOSItems(POSItems pOSItems) { if (_user == null || !_user.rights.CreateRights) { return(Unauthorized()); } if (!_validator.ValidateItem(pOSItems)) { return(BadRequest(new BadRequestObjectResult(_validator))); } if (POSItemsExists(pOSItems.Id)) { _validator.SetMessage("Entry does not exist. Are you trying to do a PUT method?"); return(BadRequest(new BadRequestObjectResult(_validator))); } _context.Items.Add(pOSItems); await _context.SaveChangesAsync().ConfigureAwait(false); return(Created(HttpContext.Request.Path, this.Create201ResponseBody(pOSItems))); }
public virtual async Task <ActionResult> Delete(int id) { var set = _context.Set <TEntity>(); var entity = await set.FindAsync(id); if (entity == null) { return(NotFound()); } set.Remove(entity); await _context.SaveChangesAsync(); return(Ok(entity)); }
[HttpDelete]// [Route("api/Productos/Eliminar")] public async Task <IHttpActionResult> Eliminar(string id) { Productos cliente = db.Productos.Where(a => a.Codpro == id).FirstOrDefault(); if (cliente == null) { return(NotFound()); } db.Entry(cliente).State = EntityState.Modified; cliente.Activo = false; await db.SaveChangesAsync(); return(Ok("OK")); }
[HttpDelete]// [Route("api/Productos/Eliminar")] public async Task <IHttpActionResult> DesactivarUsuario(string nombre) { Usuarios user = db.Usuarios.Where(a => a.Nombre == nombre).FirstOrDefault(); if (user == null) { return(NotFound()); } db.Entry(user).State = EntityState.Modified; user.Activo = false; await db.SaveChangesAsync(); return(Ok("OK")); }
[HttpDelete]// [Route("api/Productos/Eliminar")] public async Task <IHttpActionResult> Eliminar(string id) { ProductosClasificacion pc = db.ProductosClasificacion.Where(a => a.CodClasificacion == id).FirstOrDefault(); if (pc == null) { return(NotFound()); } db.ProductosClasificacion.Remove(pc); await db.SaveChangesAsync(); return(Ok("OK")); }
public async Task <TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) { var savedEntity = DbSet.Add(entity).Entity; if (autoSave) { await Context.SaveChangesAsync(cancellationToken); } return(savedEntity); }
[HttpDelete]// [Route("api/Productos/Eliminar")] public async Task <IHttpActionResult> Eliminar(int id) { Clientes cliente = db.Clientes.Where(a => a.CodCliente == id).FirstOrDefault(); if (cliente == null) { return(NotFound()); } db.Clientes.Remove(cliente); try { await db.SaveChangesAsync(); }catch (Exception ex) { throw ex; } return(Ok("OK")); }
public async Task SaveEventAndChangesAsync(IntegrationEvent evt) { _logger.LogInformation("----- POSIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id); await ResilientTransaction.New(_posContext, _logger).ExecuteAsync(async() => { // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction try { if (await _posContext.SaveChangesAsync() <= 0) { _logger.LogError("----- POSIntegrationEventService {0}", "Not can saved in Db"); } } catch (DbUpdateException e) { _logger.LogError("***** Error In SaveChangesAsync Process {0}", e.Message); } await _eventLogService.SaveEventAsync(@event: evt, transaction: Guid.NewGuid()); }); }
public async Task <int> Complete() { return(await _context.SaveChangesAsync()); }