public async Task <IActionResult> PutAccount(int id, Account account) { if (id != account.BankAccountID) { return(BadRequest()); } _context.Entry(account).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBank(int id, Bank bank) { if (id != bank.BankId) { return(BadRequest()); } _context.Entry(bank).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BankExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDepartments(int id, Departments departments) { if (id != departments.departmentsID) { return(BadRequest()); } _context.Entry(departments).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProyecto(int id, ProyectoDTO proyectoDTO) { var proyecto = _mapper.Map <Proyecto>(proyectoDTO); //Control: fecha de inicio debe ser menor que fecha de finalizacion var result = System.DateTime.Compare(proyecto.FechaInicio, proyecto.FechaFinalizacion); if (result > 0) { return(BadRequest(new { message = "La fecha de inicio debe ser anterior a su finalizacion" })); } _context.Entry(proyecto).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); }
public async Task <IActionResult> PutCertificationScheme(string id, CertificationScheme certificationScheme) { if (id != certificationScheme.name) { return(BadRequest()); } _context.Entry(certificationScheme).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CertificationSchemeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCliente(int id, Cliente cliente) { if (id != cliente.clienteID) { return(BadRequest()); } _context.Entry(cliente).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClienteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutTeacher(int id, Teacher teacher) { if (id != teacher.TeacherID) { return(BadRequest()); } _context.Entry(teacher).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeacherExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBankAccount([FromRoute] int id, [FromBody] BankAccount bankAccount) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bankAccount.BankAccountID) { return(BadRequest()); } _context.Entry(bankAccount).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BankAccountExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutKlinik([FromRoute] int id, [FromBody] Klinik klinik) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != klinik.KlinikID) { return(BadRequest()); } _context.Entry(klinik).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!KlinikExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutItem(int id, Item item) { if (id != item.ItemID) { return(BadRequest()); } _context.Entry(item).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutLandmarks(int id, Landmark landmarks) { if (id != landmarks.Landmark_Id) { return(BadRequest()); } _context.Entry(landmarks).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LandmarksExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Putattribute_value(string id, attribute_value attribute_value) { if (id != attribute_value.attribute_value_code) { return(BadRequest()); } _context.Entry(attribute_value).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!attribute_valueExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutConcert(int id, [FromBody] Concert concert) { if (id != concert.Id) { ModelState.AddModelError("Id", "Invalid Id"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (concert.Tickets.Count > 0) { foreach (Ticket ticket in concert.Tickets) { _context.Entry(ticket).State = EntityState.Modified; } } _context.Entry(concert).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConcertExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <bool> CreateOrUpdate(ProductDTO dto) { if (dto.ID > 0 && !IsExist(dto.ID)) { return(false); } var product = new Product { Name = dto.Name, Price = dto.Price }; if (dto.CompanyID.HasValue) { var company = await _context.Companies.FindAsync(dto.CompanyID.Value); if (company != null) { product.Company = company; } } ///////// orders///// if (dto.Orders.Any()) { var orders = new List <Order>(); foreach (OrderDTO order in dto.Orders) { orders.Add(await _context.Orders.FindAsync(order.OrderID)); } if (orders.Any()) { product.Orders = orders; } } ///////////////////// if (dto.ID > 0) { _context.Entry(product).State = EntityState.Modified; } else { _context.Products.Add(product); } await _context.SaveChangesAsync(); return(true); }
public async Task <bool> CreateOrUpdate(UserDTO dto) { // for Update request only!!! // check if User exists if (dto.ID > 0 && !IsExist(dto.ID)) { return(false); } var user = new User { ID = dto.ID, FirstName = dto.FirstName, LastName = dto.LastName, Email = dto.Email }; // Load Company if (dto.CompanyID.HasValue) { var company = await _context.Companies.FindAsync(dto.CompanyID.Value); if (company != null) { user.Company = company; } } // Update Request if (dto.ID > 0) { _context.Entry(user).State = EntityState.Modified; } // Insert Request else { _context.Users.Add(user); } await _context.SaveChangesAsync(); return(true); }
public void UpdateConcert(Concert concert) { /*entityToUpdate = _context.Concert * .Include(a => a.Tickets) * .Single(b => b.Id == entityToUpdate.Id); * * // update the properties * entityToUpdate.TourName = entity.TourName; * entityToUpdate.Stage = entity.Stage; * entityToUpdate.EventDate = entity.EventDate; * entityToUpdate.NumberTicketsAvailable = entity.NumberTicketsAvailable; * entityToUpdate.TicketPrice = entity.TicketPrice; * entityToUpdate.Artist = entity.Artist; * * // ************* TICKETS LIST ************* * * //entityToUpdate.Tickets = * * //List<Ticket> Tickets = _context.ConcertTickets.ToList(); * //usersList.ForEach(a => { a.isAdult = 1; }); * //_context.SaveChanges(); * * * var deletedBooks = entityToUpdate.Tickets.Except(entity.Tickets).ToList(); * var addedBooks = entity.Tickets.Except(entityToUpdate.Tickets).ToList(); * * deletedBooks.ForEach(bookToDelete => * entityToUpdate.Tickets.Remove( * entityToUpdate.Tickets * .First(b => b.Id == bookToDelete.Id))); * * foreach (var addedBook in addedBooks) * { * _context.Entry(addedBook).State = EntityState.Added; * } */ context.Entry(concert).State = EntityState.Modified; }
public async Task <bool> CreateOrUpdate(OrderDTO dto) { if (dto.ID > 0 && !IsExist(dto.ID)) { return(false); } var order = new Order { OrderID = dto.OrderID, CreateDate = dto.CreateDate, ShipDate = dto.ShipDate, Price = dto.Price }; if (dto.ProductID.HasValue) { var product = await _context.Products.FindAsync(dto.ProductID.Value); if (product != null) { order.Product = product; } } if (dto.ID > 0) { _context.Entry(order).State = EntityState.Modified; } else { _context.Orders.Add(order); } await _context.SaveChangesAsync(); return(true); }
public void Update(T t) { table.Attach(t); _context.Entry(t).State = EntityState.Modified; _context.SaveChanges(); }