Exemplo n.º 1
0
        public ActionResult Update(DesignationViewModel designationVm)
        {
            ApiResult <Designation> apiResult;

            if (ModelState.IsValid)
            {
                if (designationVm.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var designation = new Designation
                        {
                            Title        = designationVm.Title,
                            DepartmentId = designationVm.DepartmentId,
                            Band         = designationVm.Band,
                            Description  = designationVm.Description,
                            MailAlias    = designationVm.MailAlias,
                            Id           = designationVm.Id
                        };
                        _designationRepository.Update(designation);
                        _unitOfWork.Commit();
                        return(designation);
                    }, "Designation updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var designation = new Designation
                        {
                            Title        = designationVm.Title,
                            DepartmentId = designationVm.DepartmentId,
                            Band         = designationVm.Band,
                            Description  = designationVm.Description,
                            MailAlias    = designationVm.MailAlias,
                            Id           = designationVm.Id
                        };
                        _designationRepository.Create(designation);
                        _unitOfWork.Commit();
                        return(designation);
                    }, "Designation created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <Designation>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }