Beispiel #1
0
        public JsonResult Index(DelegateModel objDelegateModel, int acid)
        {
            bool bStatusFlag     = false;
            int  nPatrialSave    = 0;
            var  ErrorDictionary = new Dictionary <string, string>();

            Common.Common    objCommon           = new Common.Common();
            LoginUserDetails objLoginUserDetails = null;

            try
            {
                if (!objCommon.ValidateCSRFForAJAX())
                {
                    return(Json(new
                    {
                        status = false,
                        msg = ErrorDictionary
                    }, JsonRequestBehavior.AllowGet));
                }
                objLoginUserDetails = (LoginUserDetails)Common.Common.GetSessionValue(ConstEnum.SessionValue.UserDetails);

                if (ModelState.IsValid)
                {
                    ViewBag.UserInfoIdFrom        = objDelegateModel.UserInfoIdFrom;
                    ViewBag.UserInfoIdTo          = objDelegateModel.UserInfoIdTo;
                    ViewBag.DelegationFrom        = objDelegateModel.DelegationFrom;
                    ViewBag.DelegationTo          = objDelegateModel.DelegationTo;
                    objDelegateModel.DelegationId = 0;

                    DelegationMasterDTO objDelegationMasterDTO = new DelegationMasterDTO();

                    Common.Common.CopyObjectPropertyByName(objDelegateModel, objDelegationMasterDTO);

                    using (DelegationMasterSL objDelegationMasterSL = new DelegationMasterSL())
                    {
                        objDelegationMasterDTO = objDelegationMasterSL.SaveDetails(objDelegationMasterDTO, nPatrialSave, objLoginUserDetails.CompanyDBConnectionString, objLoginUserDetails.LoggedInUserID);
                        bStatusFlag            = true;
                        ErrorDictionary.Add("id", Convert.ToString(objDelegationMasterDTO.DelegationId));
                    }
                }
                else
                {
                    ErrorDictionary = GetModelStateErrorsAsString();
                }
            }catch (Exception e)
            {
                ModelState.Remove("KEY");
                ModelState.Add("KEY", new ModelState());
                ModelState.Clear();
                string sErrMessage = Common.Common.getResource(e.InnerException.Data[0].ToString());
                ModelState.AddModelError("error", sErrMessage);
                ErrorDictionary = GetModelStateErrorsAsString();
            }
            finally
            {
                objLoginUserDetails = null;
            }

            return(Json(new
            {
                status = bStatusFlag,
                msg = ErrorDictionary,
                user_action = acid
            }));
        }
Beispiel #2
0
        public ActionResult Edit(int acid, int[] chkActivity, DelegateModel objDelegateModel)
        {
            int nPartialSave = 1;

            DataTable tblDelefationDetailsActivity = null;

            DelegationMasterDTO objDelegationMasterDTO = null;
            LoginUserDetails    objLoginUserDetails    = null;

            try
            {
                tblDelefationDetailsActivity = new DataTable("RoleActivityType");
                tblDelefationDetailsActivity.Columns.Add(new DataColumn("RoleId", typeof(int)));
                tblDelefationDetailsActivity.Columns.Add(new DataColumn("ActivityId", typeof(int)));

                objLoginUserDetails = (LoginUserDetails)Common.Common.GetSessionValue(ConstEnum.SessionValue.UserDetails);

                objDelegationMasterDTO = new DelegationMasterDTO();
                Common.Common.CopyObjectPropertyByName(objDelegateModel, objDelegationMasterDTO);

                using (DelegationMasterSL objDelegationMasterSL = new DelegationMasterSL())
                {
                    objDelegationMasterDTO = objDelegationMasterSL.SaveDetails(objDelegationMasterDTO, nPartialSave, objLoginUserDetails.CompanyDBConnectionString, objLoginUserDetails.LoggedInUserID);

                    if (chkActivity != null && chkActivity.Length > 0)
                    {
                        DataRow row = null;
                        foreach (int ActivityId in chkActivity)
                        {
                            row               = tblDelefationDetailsActivity.NewRow();
                            row["RoleId"]     = objDelegationMasterDTO.DelegationId;
                            row["ActivityId"] = ActivityId;
                            tblDelefationDetailsActivity.Rows.Add(row);
                        }
                        row = null;
                    }
                    if (chkActivity != null && chkActivity.Length > 0)
                    {
                        objDelegationMasterSL.DelegationDetailsSaveDelete(objLoginUserDetails.CompanyDBConnectionString, tblDelefationDetailsActivity, objLoginUserDetails.LoggedInUserID);
                    }
                }

                // TODO: Add insert logic here
                // return RedirectToAction("Edit", "Delegate", new { id = id });
                return(RedirectToAction("index", "Delegate", new { acid = ConstEnum.UserActions.DELEGATION_MASTER_VIEW }));
            }
            catch (Exception e)
            {
                GenerateDelegationDetails(Convert.ToInt32(objDelegateModel.DelegationId), Convert.ToInt32(objDelegateModel.UserInfoIdFrom), Convert.ToInt32(objDelegateModel.UserInfoIdTo));
                string sErrMessage = Common.Common.getResource(e.InnerException.Data[0].ToString());
                ModelState.AddModelError("error", sErrMessage);
                return(View("Edit", objDelegateModel));
            }
            finally
            {
                tblDelefationDetailsActivity = null;

                objDelegationMasterDTO = null;
                objLoginUserDetails    = null;
            }
        }