public ActionResult Create(ViewModel.FormaPagamentoVM model) { if (string.IsNullOrEmpty(model.nmFormaPagamento)) { ModelState.AddModelError("nmFormaPagamento", "Por favor informe a forma de pagamento!"); } if (model.nmFormaPagamento != null) { if (string.IsNullOrEmpty(model.nmFormaPagamento.Trim())) { ModelState.AddModelError("nmFormaPagamento", "Por favor informe o nome da forma de pagamento!"); } } if (ModelState.IsValid) { try { //Setando as datas atuais; var dtAtual = DateTime.Today; model.dtCadastro = dtAtual.ToString("dd/MM/yyyy HH:mm"); model.dtAtualizacao = dtAtual.ToString("dd/MM/yyyy HH:mm"); //Populando o objeto para salvar; var obj = model.VM2E(new Models.FormaPagamento()); //Instanciando e chamando a DAO para salvar o objeto país no banco; var daoformaPagamentos = new DAOFormaPagamento(); if (daoformaPagamentos.Create(obj)) { TempData["message"] = "Registro inserido com sucesso!"; TempData["type"] = "sucesso"; } return(RedirectToAction("Index")); } catch (Exception ex) { this.AddFlashMessage(ex.Message, FlashMessage.ERROR); return(View(model)); } } return(View(model)); }
public ActionResult Edit(int id, ViewModel.FormaPagamentoVM model) { if (string.IsNullOrEmpty(model.nmFormaPagamento)) { ModelState.AddModelError("nmformaPagamento", "Por favor informe o nome do país!"); } if (model.nmFormaPagamento != null) { if (string.IsNullOrEmpty(model.nmFormaPagamento.Trim())) { ModelState.AddModelError("nmFormaPagamento", "Por favor informe o nome da forma de pagamento!"); } } if (ModelState.IsValid) { try { //Instanciando e chamando a DAO para salvar o objeto país no banco; var daoformaPagamentos = new DAOFormaPagamento(); model.dtAtualizacao = DateTime.Today.ToString("dd/MM/yyyy HH:mm"); //Populando o objeto para alterar; var bean = daoformaPagamentos.GetFormaPagamentosByID(id); var obj = model.VM2E(bean); if (daoformaPagamentos.Edit(obj)) { TempData["message"] = "Registro alterado com sucesso!"; TempData["type"] = "sucesso"; } return(RedirectToAction("Index")); } catch (Exception ex) { this.AddFlashMessage(ex.Message, FlashMessage.ERROR); return(View(model)); } } return(View(model)); }