public ActionResult RegistrarMudanca(MudancaViewModel vm) { Mudanca mudanca = new Mudanca(); var validacao = Util.Util.ValidarCamposMudanca(vm); var hora = DateTime.Parse(vm.Hora); var data = vm.Dia; var mudancaNoDia = unitOfWork.Mudancas.GetMudancaPorData(data); if (!validacao && mudancaNoDia == null) { mudanca = Mudanca.Criar(vm.Nome, data, hora, vm.TipoMudancaId, vm.Comentario, User.Identity.GetUserId()); unitOfWork.Mudancas.Add(mudanca); unitOfWork.Complete(); vm.Sucesso = true; NotificarMudanca(mudanca); } if (mudancaNoDia != null) { vm.ErrorMudanca = true; } if (validacao) { vm.ErrorValidacao = true; } vm.TiposMudanca = unitOfWork.TiposMudanca.GetAllTiposMudanca(); vm.MinhasMudancas = unitOfWork.Mudancas.GetMudancasPorId(User.Identity.GetUserId()); return(View("Index", vm)); }
public ActionResult Index() { var vm = new MudancaViewModel(); var nomeUsuario = User.Identity.Name; vm.NomeUsuarioLogado = nomeUsuario.Split('-')[0]; vm.ErrorValidacao = false; vm.Dia = DateTime.Now; vm.Hora = DateTime.Now.ToString("HH:mm"); vm.TiposMudanca = unitOfWork.TiposMudanca.GetAllTiposMudanca(); vm.MinhasMudancas = unitOfWork.Mudancas.GetMudancasPorId(User.Identity.GetUserId()); return(View(vm)); }
public static bool ValidarCamposMudanca(MudancaViewModel vm) { var erroValidacao = false; var data = new DateTime(); if (!string.IsNullOrEmpty(vm.Dia.ToString())) { data = DateTime.Parse(vm.Dia.ToString()); } if (string.IsNullOrEmpty(vm.Nome) || vm.TipoMudancaId == 0 || string.IsNullOrEmpty(vm.Dia.ToString()) || string.IsNullOrEmpty(vm.Hora)) { erroValidacao = true; } else if (data.Date < DateTime.Now.Date) { erroValidacao = true; } return(erroValidacao); }