Exemplo n.º 1
0
        public ActionResult Edit(EmprestimoViewModel emprestimoViewModel)
        {
            if (ModelState.IsValid)
            {
                var emprestimOriginal = _wcfServiceClient.GetEmprestimoById(emprestimoViewModel.EmprestimoId);
                var emprestimoEntity  = Mapper.Map <EmprestimoViewModel, Emprestimo>(emprestimoViewModel);

                if (emprestimOriginal.MaterialId != emprestimoEntity.MaterialId)
                {
                    emprestimoEntity.DataDevolver = CalculaDataDevolucao(emprestimoEntity);
                }

                _wcfServiceClient.UpdateEmprestimo(emprestimoEntity);

                return(RedirectToAction("Index"));
            }

            emprestimoViewModel.Clientes  = GetClientesDropDownList();
            emprestimoViewModel.Materiais = GetMateraisDropDownList();
            return(View(emprestimoViewModel));
        }