예제 #1
0
        public void Execute(NapraviNoviTip request)
        {
            if (request == null)
            {
                throw new NullReferenceException("Tip");
            }
            if (Context.Tipovi.Any(m => m.Type == request.Tip))
            {
                throw new EntityAlreadyExists("Tip");
            }

            var tip = new Tip
            {
                Type        = request.Tip,
                DateCreated = DateTime.Now
            };

            try
            {
                Context.Tipovi.Add(tip);
                Context.SaveChanges();
            }
            catch (Exception)
            {
                throw new EntryPointNotFoundException();
            }
        }
예제 #2
0
 public IActionResult Post([FromBody] NapraviNoviTip tip)
 {
     try
     {
         _addNewTypeCommand.Execute(tip);
         return(Ok());
     }
     catch (EntityAlreadyExists e)
     {
         return(UnprocessableEntity(e.Message));
     }
 }
예제 #3
0
 public IActionResult Put(int id, [FromBody] NapraviNoviTip tip)
 {
     try
     {
         tip.TipId = id;
         _editTypeCommand.Execute(tip);
         return(Ok());
     }
     catch (Exception e)
     {
         return(UnprocessableEntity(e.Message));
     }
 }
예제 #4
0
        public void Execute(NapraviNoviTip request)
        {
            var type = Context.Tipovi.Find(request.TipId);

            if (Context.Tipovi.Where(x => x.Id != request.TipId).Any(t => t.Type == request.Tip))
            {
                throw new EntityAlreadyExists("Tip");
            }

            try
            {
                type.DateModified = DateTime.Now;
                type.Type         = request.Tip;
                Context.SaveChanges();
            }
            catch
            {
                throw new NullReferenceException("Something went wrong with update in db");
            }
        }