public async Task <ActionResult <ReceptionGet> > PutReceptions([FromBody] ReceptionPost reception) { var result = await _receptionService.UpdateAsync1(reception); if (result == null) { return(BadRequest()); } return(Ok(result)); }
public async Task <Reception> AddAsync1(ReceptionPost reception) { var _reception = new Reception { Specialty = await _db.Specialties.FindAsync(reception.SpecialtyId), DateOfReceipt = Convert.ToDateTime(reception.DateOfReceipt), Employee = await _db.Employees.Include(x => x.EmployeeSpecialties).FirstOrDefaultAsync(x => x.EmployeeId == reception.EmployeeId), Client = reception.Client, Status = Status.Pending, Registered = DateTime.UtcNow }; await _db.Receptions.AddAsync(_reception); await _db.SaveChangesAsync(); _emailService.Send("", _reception.Status, _reception.Registered.ToString()); return(_reception); }
public async Task <ReceptionGet> UpdateAsync1(ReceptionPost reception) { var _reception = await _db.Receptions.Include(x => x.Client) .Include(x => x.Specialty) .Include(x => x.Employee).FirstOrDefaultAsync(x => x.ReceptionId == reception.ReceptionId); var _receptionGet = new ReceptionGet(); if (_reception != null) { _reception.DateOfReceipt = Convert.ToDateTime(reception.DateOfReceipt); _reception.Status = reception.Status; try { await _db.SaveChangesAsync(); _receptionGet = new ReceptionGet() { ReceptionId = _reception.ReceptionId, Client = _reception.Client, DateOfReceipt = _reception.DateOfReceipt, EmployeeId = _reception.Employee.EmployeeId, EmployeeFullName = _reception.Employee.FullName, SpecialtyId = _reception.Specialty.SpecialtyId, SpecialtyName = _reception.Specialty.Name, Registered = _reception.Registered, Status = _reception.Status }; } catch (DbUpdateConcurrencyException) when(!ReceptionExists(reception.ReceptionId)) { return(null); } return(_receptionGet); } return(null); }