コード例 #1
0
ファイル: ClientController.cs プロジェクト: radtek/eTrac
        public ActionResult Index(QRCModel ObjUserModel)
        {
            DARModel objDAR = null;

            try
            {
                eTracLoginModel ObjLoginModel = null;
                if (Session["eTrac"] != null)
                {
                    ObjLoginModel = (eTracLoginModel)(Session["eTrac"]);
                }

                //if (ModelState.IsValid)
                //{

                if (ObjUserModel != null && ObjUserModel.UserModel != null) //&& ObjUserModel.UserModel.UserId == 0
                {
                    if (ObjUserModel.UserModel.UserId == 0)
                    {
                        #region password

                        ObjUserModel.UserModel.Password = _ICommonMethod.CreateRandomPassword();

                        /*
                         * ObjUserModel.UserModel.Password = Guid.NewGuid().ToString();
                         * ObjUserModel.UserModel.Password = ObjUserModel.UserModel.Password.Length > pwdmaxlendth ? ObjUserModel.UserModel.Password.Substring(0, pwdmaxlendth) : ObjUserModel.UserModel.Password;
                         * ObjUserModel.UserModel.Password = Cryptography.GetEncryptedData(ObjUserModel.UserModel.Password, true);
                         * //ObjUserModel.UserModel.Password = (!string.IsNullOrEmpty(ObjUserModel.UserModel.Password)) ? Cryptography.GetEncryptedData(ObjUserModel.UserModel.Password, true) : ObjUserModel.UserModel.Password;
                         */
                        #endregion password

                        ObjUserModel.UserModel.CreatedBy   = ObjLoginModel.UserId;
                        ObjUserModel.UserModel.CreatedDate = DateTime.UtcNow;
                        ObjUserModel.UserModel.IsDeleted   = false;

                        objDAR                 = new DARModel();
                        objDAR.LocationId      = ObjLoginModel.LocationID;
                        objDAR.UserId          = ObjLoginModel.UserId;
                        objDAR.CreatedBy       = ObjLoginModel.UserId;
                        objDAR.CreatedOn       = DateTime.UtcNow;
                        objDAR.ActivityDetails = DarMessage.NewManagerCreatedDar(ObjLoginModel.Location);
                    }
                    else
                    {
                        ObjUserModel.UserModel.ModifiedBy   = ObjLoginModel.UserId;
                        ObjUserModel.UserModel.ModifiedDate = DateTime.UtcNow;
                        ObjUserModel.UserModel.IsDeleted    = false;

                        objDAR                 = new DARModel();
                        objDAR.LocationId      = ObjLoginModel.LocationID;
                        objDAR.UserId          = ObjLoginModel.UserId;
                        objDAR.ModifiedBy      = ObjLoginModel.UserId;
                        objDAR.ModifiedOn      = DateTime.UtcNow;
                        objDAR.ActivityDetails = DarMessage.ManagerUpdatedDar(ObjLoginModel.Location);
                    }

                    long QRCID = 0;
                    //Result result = _IClientManager.SaveClient(ObjUserModel.UserModel, out QRCID, true, objDAR);
                    Result result = _IClientManager.SaveClient(ObjUserModel.UserModel, out QRCID, true, objDAR, ObjLoginModel.LocationID, ObjLoginModel.UserId, "");

                    if (result == Result.Completed)
                    {
                        ViewBag.Message           = CommonMessage.SaveSuccessMessage();
                        ViewBag.AlertMessageClass = ObjAlertMessageClass.Success;
                        ModelState.Clear();
                        //return View("ITAdministrator");//return RedirectToAction("Create ", "GlobalAdmin");
                        ObjUserModel = _ICommonMethod.LoadInvitedUser(string.Empty);
                    }
                    else if (result == Result.DuplicateRecord)
                    {
                        ViewBag.Message           = CommonMessage.DuplicateRecordEmailIdMessage();
                        ViewBag.AlertMessageClass = ObjAlertMessageClass.Info; // store the message for successful in tempdata to display in view.
                    }
                    else if (result == Result.UpdatedSuccessfully)
                    {
                        ViewBag.Message           = CommonMessage.UpdateSuccessMessage();
                        ViewBag.AlertMessageClass = ObjAlertMessageClass.Success;// store the message for successful in tempdata to display in view.
                        ModelState.Clear();
                        //return RedirectToAction("index", "GlobalAdmin");
                    }
                    else
                    {
                        ViewBag.Message           = CommonMessage.FailureMessage();
                        ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger;// store the failure message in tempdata to display in view.
                    }
                }
                else
                {
                    ViewBag.Message = CommonMessage.InvalidEntry();
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message           = ex.Message;
                ViewBag.AlertMessageClass = ObjAlertMessageClass.Danger;
            }
            finally
            {
                ViewBag.Country = _ICommonMethod.GetAllcountries();

                ViewBag.JobTitleList = _ICommonMethod.GetGlobalCodeData("UserJobTitle");
                ViewBag.LocationList = _IGlobalAdmin.GetAllLocationNew();

                //System.Data.Entity.Core.Objects.ObjectParameter paramTotalRecords = new System.Data.Entity.Core.Objects.ObjectParameter("TotalRecords", typeof(int));
                //ObjUserModel.JobTitleList = _ICommonMethod.GetGlobalCodeData("JOBTITLE");
                //ObjUserModel.LocationList = _IGlobalAdmin.GetAllLocationList(0, "GetAllLocation", 1, 10000, "LocationName", "desc", "", paramTotalRecords);
                //paramTotalRecords = null;
            }

            ViewBag.UpdateMode = false;
            //ObjUserModel.UserModel = _IClientManager.GetClientByID(ObjUserModel.UserModel.UserId, "GetUserByID", null, null, null, null, null);
            return(View("myClient", ObjUserModel));
        }