public void Execute(NapraviIzmeniMarku request) { if (request == null) { throw new NullReferenceException("Marka"); } if (Context.Marke.Any(m => m.MarkaAutomobila == request.Marka)) { throw new EntityAlreadyExists("Marka"); } var marka = new Marka { MarkaAutomobila = request.Marka, DateCreated = DateTime.Now }; try { Context.Marke.Add(marka); Context.SaveChanges(); } catch (Exception) { throw new EntryPointNotFoundException(); } }
public IActionResult Post([FromBody] NapraviIzmeniMarku marka) { try { _addNewBrandCommand.Execute(marka); return(Ok()); } catch (EntityAlreadyExists e) { return(UnprocessableEntity(e.Message)); } }
public IActionResult Put(int id, [FromBody] NapraviIzmeniMarku marka) { try { marka.MarkaId = id; _editBrandCommand.Execute(marka); return(Ok()); } catch (Exception e) { return(UnprocessableEntity(e.Message)); } }
public void Execute(NapraviIzmeniMarku request) { var brands = Context.Marke.Find(request.MarkaId); if (Context.Marke.Where(x => x.Id != request.MarkaId).Any(m => m.MarkaAutomobila == request.Marka)) { throw new EntityAlreadyExists("Model"); } try { brands.DateModified = DateTime.Now; brands.MarkaAutomobila = request.Marka; Context.SaveChanges(); } catch { throw new NullReferenceException("Something went wrong with update in db"); } }