public async Task <IActionResult> CreateNewReclamations(ReclamationDto newReclamationDto) { if (!ModelState.IsValid) { return(BadRequest()); } var soldDevice = await _unitOfWork.SoldDevices.GetSoldDeviceAsync(newReclamationDto.SoldDeviceId); if (soldDevice.ExpiredWarranty() == true) { return(BadRequest("Warranty for this device has expired.")); } var reclamation = mapper.Map <ReclamationDto, Reclamations>(newReclamationDto); if (User.IsInRole(RoleName.AgentRoleName)) { reclamation.Agent = _unitOfWork.Employees.GetAgent(reclamation.AgentId); reclamation.Create(); } _unitOfWork.Reclamations.Add(reclamation); _unitOfWork.Complete(); newReclamationDto.Id = reclamation.Id; return(Ok()); }
public async Task <IActionResult> UpdateReclamation(int id, ReclamationDto reclamationDbo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var reclamationInDb = await _unitOfWork.Reclamations.GetReclamationAsync(id); if (reclamationInDb == null) { return(NotFound()); } mapper.Map(reclamationDbo, reclamationInDb); _unitOfWork.Complete(); return(Ok()); }