public void Execute(CreateDobavljacDTO request) { if (_context.Dobavljacs.Any(k => k.Naziv.ToLower().Contains(request.Naziv.ToLower()))) { throw new EntityAlreadyExistsException("This supplier "); } _context.Dobavljacs.Add(new Dobavljac { Naziv = request.Naziv, ModifiedOn = null }); _context.SaveChanges(); }
public ActionResult Post([FromBody] CreateDobavljacDTO dto) { try { _createDobavljac.Execute(dto); return(StatusCode(201)); } catch (EntityAlreadyExistsException e) { return(UnprocessableEntity(e.Message)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }