public void Execute(NapraviVrstuGoriva request) { if (request == null) { throw new NullReferenceException("Gorivo"); } if (Context.VrsteGoriva.Any(g => g.Naziv == request.VrstaGoriva)) { throw new EntityAlreadyExists("Gorivo"); } var gorivo = new Gorivo { Naziv = request.VrstaGoriva, DateCreated = DateTime.Now }; try { Context.VrsteGoriva.Add(gorivo); Context.SaveChanges(); } catch (Exception) { throw new EntryPointNotFoundException(); } }
public IActionResult Post([FromBody] NapraviVrstuGoriva gorivo) { try { _addFuelCommand.Execute(gorivo); return(Ok()); } catch (EntityAlreadyExists e) { return(UnprocessableEntity(e.Message)); } }
public IActionResult Put(int id, [FromBody] NapraviVrstuGoriva gorivo) { try { gorivo.GorivoId = id; _editFuelCommand.Execute(gorivo); return(Ok()); } catch (Exception e) { return(UnprocessableEntity(e.Message)); } }
public void Execute(NapraviVrstuGoriva request) { var fuels = Context.VrsteGoriva.Find(request.GorivoId); if (Context.VrsteGoriva.Where(x => x.Id != request.GorivoId).Any(g => g.Naziv == request.VrstaGoriva)) { throw new EntityAlreadyExists("Gorivo"); } try { fuels.DateModified = DateTime.Now; fuels.Naziv = request.VrstaGoriva; Context.SaveChanges(); } catch { throw new NullReferenceException("Something went wrong with update in db"); } }