Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
 public IActionResult Post([FromBody] NapraviVrstuGoriva gorivo)
 {
     try
     {
         _addFuelCommand.Execute(gorivo);
         return(Ok());
     }
     catch (EntityAlreadyExists e)
     {
         return(UnprocessableEntity(e.Message));
     }
 }
Esempio n. 3
0
 public IActionResult Put(int id, [FromBody] NapraviVrstuGoriva gorivo)
 {
     try
     {
         gorivo.GorivoId = id;
         _editFuelCommand.Execute(gorivo);
         return(Ok());
     }
     catch (Exception e)
     {
         return(UnprocessableEntity(e.Message));
     }
 }
Esempio n. 4
0
        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");
            }
        }