public void PutValidation(LookupUpdateDTO lookupDTO) { if (lookupDTO.Id <= 0) { throw new ServiceException(ExceptionMessages.LOOKUP_ID_NOT_AVAILABLE); } else if (string.IsNullOrEmpty(lookupDTO.Name)) { throw new ServiceException(ExceptionMessages.LOOKUP_NAME_CANNOT_BE_BLANK); } else if (string.IsNullOrEmpty(lookupDTO.Type)) { throw new ServiceException(ExceptionMessages.TYPE_CANNOT_BE_BLANK); } }
public void Update(LookupUpdateDTO lookupDTO) { var lookup = _context.Lookups.FirstOrDefault(x => x.Id == lookupDTO.Id); if (lookup == null) { throw new ServiceException(ExceptionMessages.LOOKUP_NOT_FOUND); } lookup.UpdatedDate = DateTime.Now; lookup.Name = lookupDTO.Name; lookup.Type = lookupDTO.Type; lookup.OrderId = lookupDTO.OrderId; _context.Update(lookup); _context.SaveChanges(); }
public IActionResult Put(LookupUpdateDTO lookupDTO) { try { _lookupService.PutValidation(lookupDTO); _lookupService.Update(lookupDTO); return(Ok()); } catch (AuthenticationException) { return(Forbid()); } catch (ServiceException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { return(BadRequest(ex.StackTrace)); } }