Esempio n. 1
0
        public IActionResult Put([FromBody] PatrimonyViewModel patrimonyViewModel)
        {
            var result = _patrimonyService.Update(patrimonyViewModel);

            SetNotifications(result.Item2);
            return(Response(result.Item1));
        }
Esempio n. 2
0
        public Tuple <PatrimonyViewModel, IReadOnlyCollection <Notification> > Add(PatrimonyViewModel viewModel)
        {
            var entity = _mapper.Map <Patrimony>(viewModel);

            if (entity.Valid)
            {
                var brand = _brandService.GetById(entity.BrandId);
                if (brand != null)
                {
                    _patrimonyRepository.Add(entity);
                    CommandResponse commandResponse = _unitOfWork.Commit();
                    if (!commandResponse.Success)
                    {
                        entity.AddNotification("", "Erro ao salvar");
                    }
                }
                else
                {
                    entity.AddNotification("Brand", "Marca nao cadastrada");
                }
            }

            AddNotifications(entity.Notifications);

            return(new Tuple <PatrimonyViewModel, IReadOnlyCollection <Notification> >(_mapper.Map <PatrimonyViewModel>(entity), entity.Notifications));
        }