public void Execute(NapraviNovModel request) { if (request == null) { throw new NullReferenceException("Model"); } if (Context.Modeli.Any(m => m.Model == request.Model)) { throw new EntityAlreadyExists("Model"); } if (!Context.Marke.Any(ma => ma.Id == request.MarkaId)) { throw new EntityAlreadyExists("Marka"); } var model = new ModelAutomobila { Model = request.Model, MarkaId = request.MarkaId, DateCreated = DateTime.Now }; try { Context.Modeli.Add(model); Context.SaveChanges(); } catch (Exception) { throw new EntryPointNotFoundException(); } }
public IActionResult Post([FromBody] NapraviNovModel model) { try { _addNewModelCommand.Execute(model); return(Ok()); } catch (EntityAlreadyExists e) { return(UnprocessableEntity(e.Message)); } }
public IActionResult Put(int id, [FromBody] NapraviNovModel model) { try { model.ModelId = id; _editModelCommand.Execute(model); return(Ok()); } catch (Exception e) { return(UnprocessableEntity(e.Message)); } }
public void Execute(NapraviNovModel request) { var models = Context.Modeli.Find(request.ModelId); if (Context.Modeli.Where(x => x.Id != request.ModelId).Any(g => g.Model == request.Model)) { throw new EntityAlreadyExists("Model"); } if (!Context.Marke.Any(m => m.Id == request.MarkaId)) { throw new EntityAlreadyExists("Marka"); } try { models.DateModified = DateTime.Now; models.Model = request.Model; Context.SaveChanges(); } catch { throw new NullReferenceException("Something went wrong with update in db"); } }