コード例 #1
0
        public async Task <IActionResult> AddEdit(int Id, ProdutoAddEditVM model)
        {
            if (!ModelState.IsValid)
            {
                await addCategoriasToModel(model);

                return(View(model));
            }
            var prod = model.ToData();

            if (Id == 0)
            {
                _produtoRepository.Add(prod);
            }
            else
            {
                prod.Id            = Id;
                prod.DataAlteracao = DateTime.Now;
                _produtoRepository.Update(prod);
            }

            await _uow.CommitAsync();;


            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <IActionResult> AddEdit(string id, ProdutoAddEditVM model)
        {
            ModelState.Remove("DataHoraRegistro");
            ModelState.Remove("IdUsuarioRegistro");

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var data = model.ToData();

            if (String.IsNullOrEmpty(id))
            {
                data.IdUsuarioRegistro = Convert.ToDecimal(HttpContextHelper.GetAuthUserId(HttpContext));
                data.DhRegistro        = Convert.ToDecimal(DateTime.Now.ToString("yyyyMMddHHmmss"));

                _produtoRepo.Add(data);
            }
            else
            {
                _produtoRepo.Update(data);
            }

            await _uow.CommitAsync();

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <Music> CreateMusic(Music newMusic)
        {
            await _unityOfWork.Musics.AddAsync(newMusic);

            await _unityOfWork.CommitAsync();

            return(newMusic);
        }
コード例 #4
0
        public async Task <IActionResult> Add(NPC_SituacaoAddVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var data = model.ToData();

            _situacaoRepo.Add(data);
            await _uow.CommitAsync();

            return(RedirectToAction("Index"));
        }
コード例 #5
0
        public async Task <IActionResult> AddEdit(int Id, UsuarioAddEditVM model)
        {
            if (!ModelState.IsValid)
            {
                await GetPerfis(model);

                return(View(model));
            }
            var usr = model.ToData();

            usr.Perfis = await MontarPerfil(model.PerfisId);

            if (Id == 0)
            {
                usr.Senha = usr.Senha.Encrypt();
                _usuarioRepository.Add(usr);
            }
            else
            {
                //tratar para não mostrar a senha no browser
                //usr.Id = Id;
                //usr.Senha = _usuarioRepository.Get(Id).Senha;
                //usr.DataAlteracao = DateTime.Now;
                // com model.toData não funcionou!!!
                var x = _usuarioRepository.Get(Id);
                x.Nome          = model.Nome;
                x.Genero        = (Genero)model.Genero;
                x.Email         = model.Email;
                x.DataAlteracao = DateTime.Now;
                x.Perfis        = usr.Perfis;

                //Usuario u = new Usuario()
                //{
                //    Id = Id,
                //    Nome = model.Nome,
                //    Genero = (Genero)model.Genero,
                //    Email = model.Email,
                //    DataAlteracao = DateTime.Now
                //};

                _usuarioRepository.Update(x);
            }
            await _uow.CommitAsync();

            return(RedirectToAction("Index"));
        }
コード例 #6
0
        public async Task <IActionResult> AddNewUser(string returnUrl, UsuarioAddEditVM model)
        {
            var data = model.ToData();

            data.HashSenha  = model.Senha.Encrypt();
            data.DhRegistro = Convert.ToDecimal(DateTime.Now.ToString("yyyyMMddHHmmss"));
            data.StUsuario  = EnumHelper.SituacaoUsuario.UA9.ToString();

            _usuarioRepo.Add(data);
            data.IdUsuarioRegistro = data.IdUsuario;

            await _uow.CommitAsync();

            await Task.Run(async() =>
            {
                int userId = Convert.ToInt32(data.IdUsuario);

                var _userToSend = new EmailFormModel()
                {
                    FromEmail = data.EmailUsuario,
                    FromName  = data.NmUsuario
                };

                // Credenciais para o envio do email
                var credentials = _credential.GetEmailCredentials();

                var credEmail = credentials.Where(k => k.Key == "Email").Select(e => e.Value).ToList().FirstOrDefault();
                var credPass  = credentials.Where(k => k.Key == "Password").Select(e => e.Value).ToList().FirstOrDefault();
                var credHost  = credentials.Where(k => k.Key == "Host").Select(e => e.Value).ToList().FirstOrDefault();
                var credPort  = credentials.Where(k => k.Key == "Port").Select(e => e.Value).ToList().FirstOrDefault();

                var _sender = new Sender(credEmail, credPass, credHost, Convert.ToInt16(credPort));

                await _sender.SendConfirmation(_userToSend, userId);
            });

            if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(View("Success", data));
            };
        }
コード例 #7
0
        public async Task <IActionResult> AddEdit(string id, SituacaoUsuarioAddEditVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var data = model.ToData();

            if (String.IsNullOrEmpty(id))
            {
                _situacaousuarioRepo.Add(data);
            }
            else
            {
                _situacaousuarioRepo.Update(data);
            }

            await _uow.CommitAsync();

            return(RedirectToAction("Index", new { message = "Adicionado com sucesso!" }));
        }
コード例 #8
0
        public async Task <IActionResult> AddEdit(string id, TipoVisualizacaoAddEditVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var data = model.ToData();

            if (String.IsNullOrEmpty(id))
            {
                _tipovisualRepo.Add(data);
            }
            else
            {
                _tipovisualRepo.Update(data);
            }

            await _uow.CommitAsync();

            return(RedirectToAction("Index"));
        }
コード例 #9
0
        public async Task <Transaction> Save(Guid userId, PostTransactionDto postTransactionDto)
        {
            var transaction = _mapper.Map <Transaction>(postTransactionDto);

            transaction.Status = TransactionStatus.Pending;
            transaction.User   = await _userService.GetById(userId);

            await _unityOfWork.TransactionRepository.AddAsync(transaction);

            await _unityOfWork.CommitAsync();

            return(transaction);
        }
コード例 #10
0
        public async Task <IActionResult> AddEdit(int Id, CategoriaAddEditVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var cat = model.ToData();

            if (Id == 0)
            {
                _categoriaRepository.Add(cat);
            }
            else
            {
                cat.Id            = Id;
                cat.DataAlteracao = DateTime.Now;
                _categoriaRepository.Update(cat);
            }

            await _uow.CommitAsync();

            return(RedirectToAction("Index"));
        }
コード例 #11
0
        public async Task <User> SignUp(PostSignUpDto postSignUpDto)
        {
            var user        = _mapper.Map <User>(postSignUpDto);
            var emailExists = await _unityOfWork.UserRepository.AnyAsync(user => user.Email == user.Email);

            if (emailExists)
            {
                throw new BusinessRuleException("Já existe um usuário com este e-mail");
            }

            user.Password  = _hashService.Hash(user.Password);
            user.LastLogin = null;
            user.IsActive  = true;

            await _unityOfWork.UserRepository.AddAsync(user);

            await _unityOfWork.CommitAsync();

            return(user);
        }
コード例 #12
0
        public async Task <IActionResult> AddEdit(decimal id, BaseConhecimentoAddEditVM model)
        {
            ModelState.Remove("IdUsuarioRegistro");
            ModelState.Remove("DataHoraRegistro");
            ModelState.Remove("SitBase");

            ViewBag.IsEditing = "N";
            if (id > 0)
            {
                ModelState.Remove("PalavraChave");
                ViewBag.IsEditing = "S";
            }

            if (!ModelState.IsValid)
            {
                await getTipoVisualizacaoSelect();
                await getSituacaoBaseSelect();
                await getProdutosBaseSelect();

                return(View(model));
            }

            var userContext = Convert.ToDecimal(HttpContextHelper.GetAuthUserId(HttpContext));

            var data = model.ToData(userContext, id);

            if (id == 0)
            {
                data.DtHrRegistro = Convert.ToDecimal(DateTime.Now.ToString("yyyyMMddHHmmss"));
                data.StBase       = EnumHelper.SituacaoBase.BA9.ToString();

                _baseconhecimentoRepo.Add(data);

                // Palavras Chave existentes
                var words = model.PalavraChave.KeyWordToArray();

                // Lista das palavras chave que foram informadas
                var wordID = new List <decimal>();

                // Verifica se a Palavra Chave informada já existe na tabela
                var wordsData = await _palavrachaveRepo.GetAsync();

                foreach (var word in words)
                {
                    decimal IdWord = wordsData
                                     .Where(c => c.Palavra.ToUpper() == word.ToUpper())
                                     .Select(c => c.IdPalavra).FirstOrDefault();

                    if (IdWord == 0)
                    {
                        // Cria a nova palavra chave
                        var plvr = new PalavraChave()
                        {
                            Palavra           = word,
                            IdUsuarioRegistro = data.IdUsuarioRegistro
                        };

                        _palavrachaveRepo.Add(plvr);

                        wordID.Add(plvr.IdPalavra);
                    }
                    else
                    {
                        wordID.Add(IdWord);
                    }
                }

                // Busca Chave
                foreach (var word in wordID)
                {
                    _buscachaveRepo.Add(new BuscaChave()
                    {
                        Id                = data.Id,
                        IdPalavra         = word,
                        IdUsuarioRegistro = data.IdUsuarioRegistro
                    });
                }
            }
            else
            {
                _baseconhecimentoRepo.Update(data);
            }

            await _uow.CommitAsync();

            return(RedirectToAction("Index"));
        }
コード例 #13
0
 public async Task DeleteArtist(Artist artist)
 {
     _unityOfWork.Artists.Remove(artist);
     await _unityOfWork.CommitAsync();
 }