示例#1
0
        public ActionResult Edit(MotivoLaudoCreateViewModel model)
        {
            Func <ViewResult> errorView = () =>
            {
                return(View(model));
            };

            if (!ModelState.IsValid)
            {
                return(errorView());
            }

            var motivoLaudo = new MotivoLaudo
            {
                Descricao     = model.Descricao,
                Ativo         = model.Ativo,
                IdMotivoLaudo = model.IdMotivoLaudo
            };

            try
            {
                _motivoLaudoService.Edit(motivoLaudo);

                return(Json(new AjaxGenericResultModel
                {
                    Success = true,
                    Message = Resources.CommonStrings.RegisterEditedSuccessMessage
                }));

                //Notify.Success();
                //return RedirectToAction("MotivoLaudo");
            }
            catch (DbUpdateException e)
                when(e.InnerException?.InnerException is OracleException sqlEx && sqlEx.Number == 1)
                {
                    Notify.Error("");

                    return(Json(new AjaxGenericResultModel
                    {
                        Success = false,
                        Message = "Já existe um motivo cadastrado com este nome."
                    }));

                    //return errorView();
                }
            catch (Exception)
            {
                return(Json(new AjaxGenericResultModel
                {
                    Success = false,
                    Message = Resources.CommonStrings.RegisterEditedErrorMessage
                }));

                //return errorView();
            }
        }
示例#2
0
        public ActionResult Create(MotivoLaudoCreateViewModel model)
        {
            Func <ViewResult> errorView = () =>
            {
                return(View(model));
            };

            if (!ModelState.IsValid)
            {
                return(errorView());
            }

            var motivoLaudo = new MotivoLaudo
            {
                Descricao = model.Descricao,
                Ativo     = model.Ativo
            };

            try
            {
                _motivoLaudoService.Add(motivoLaudo);

                Notify.Success(Resources.CommonStrings.RegisterCreatedSuccessMessage);
                return(RedirectToAction("MotivoLaudo"));
            }
            catch (DbUpdateException e)
                when(e.InnerException?.InnerException is OracleException sqlEx && sqlEx.Number == 1)
                {
                    Notify.Error("Já existe um motivo cadastrado com este nome.");

                    return(errorView());
                }
            catch (Exception e)
            {
                Notify.Error(Resources.CommonStrings.RegisterCreatedErrorMessage);

                return(errorView());
            }
        }