Exemplo n.º 1
0
        public Tuple <BrandViewModel, IReadOnlyCollection <Notification> > Add(BrandViewModel viewModel)
        {
            Brand entity = _mapper.Map <Brand>(viewModel);

            if (entity.Valid)
            {
                var brand = _brandRepository.Find(x => x.Name.ToLower() == entity.Name.ToLower()).ToList();
                if (!brand.Any())
                {
                    _brandRepository.Add(entity);
                    CommandResponse commandResponse = _unitOfWork.Commit();
                    if (!commandResponse.Success)
                    {
                        entity.AddNotification("", "Erro ao salvar");
                    }
                }

                else
                {
                    entity.AddNotification("Brand", "Marca ja cadastrada");
                }
            }

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