コード例 #1
0
ファイル: PoController.cs プロジェクト: denapurnama/Incubator
        public JsonResult AddEditSave(string screenMode, PakAnas.Models.Approval data)
        {
            AjaxResult ajaxResult = new AjaxResult();
            RepoResult repoResult = null;

            IDBContext db = databaseManager.GetContext();

            try
            {
                db.BeginTransaction();

                ajaxResult = Validation(data); //Validasi Controller

                if (AjaxResult.VALUE_SUCCESS.Equals(ajaxResult.Result))
                {
                    if (CommonConstant.SCREEN_MODE_ADD.Equals(screenMode))
                    {
                        repoResult = approvalRepo.Insert(GetLoginUserId(), data);
                    }
                    else if (CommonConstant.SCREEN_MODE_EDIT.Equals(screenMode))
                    {
                        repoResult = approvalRepo.Update(GetLoginUserId(), data);
                    }

                    CopyPropertiesRepoToAjaxResult(repoResult, ajaxResult);

                    if (AjaxResult.VALUE_ERROR.Equals(ajaxResult.Result))
                    {
                        db.AbortTransaction();
                    }
                    else
                    {
                        db.CommitTransaction();
                    }
                }
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                ajaxResult.Result   = AjaxResult.VALUE_ERROR;
                ajaxResult.ErrMesgs = new string[] {
                    string.Format("{0} = {1}", ex.GetType().FullName, ex.Message)
                };
            }
            finally
            {
                db.Close();
            }

            return(Json(ajaxResult));
        }
コード例 #2
0
ファイル: PoController.cs プロジェクト: denapurnama/Incubator
        public JsonResult GetByKey(long approvalId)
        {
            AjaxResult ajaxResult = new AjaxResult();

            PakAnas.Models.Approval result = null;

            try
            {
                result = approvalRepo.GetByKeyWithDtl(approvalId);

                if (result == null)
                {
                    ajaxResult.Result   = AjaxResult.VALUE_ERROR;
                    ajaxResult.ErrMesgs = new string[] {
                        string.Format("No Data with the selected key found," +
                                      "please refresh the screen first")
                    };

                    return(Json(ajaxResult));
                }

                ajaxResult.Result = AjaxResult.VALUE_SUCCESS;
                ajaxResult.Params = new object[] {
                    result
                };
            }
            catch (Exception ex)
            {
                ajaxResult.Result   = AjaxResult.VALUE_ERROR;
                ajaxResult.ErrMesgs = new string[] {
                    string.Format("{0} = {1}", ex.GetType().FullName, ex.Message)
                };
            }

            return(Json(ajaxResult));
        }