Beispiel #1
0
        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();
            }
        }
Beispiel #2
0
 public IActionResult Post([FromBody] NapraviIzmeniMarku marka)
 {
     try
     {
         _addNewBrandCommand.Execute(marka);
         return(Ok());
     }
     catch (EntityAlreadyExists e)
     {
         return(UnprocessableEntity(e.Message));
     }
 }
Beispiel #3
0
 public IActionResult Put(int id, [FromBody] NapraviIzmeniMarku marka)
 {
     try
     {
         marka.MarkaId = id;
         _editBrandCommand.Execute(marka);
         return(Ok());
     }
     catch (Exception e)
     {
         return(UnprocessableEntity(e.Message));
     }
 }
Beispiel #4
0
        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");
            }
        }