Example #1
0
        public ActionResult CreateClient(UserModel UserModel)
        {
            //Commented by Bhushan Dod for Code review bcoz unused variable.
            //ObjectParameter paramTotalrecord = new ObjectParameter("TotalRecords", typeof(int));
            var      action = this.ControllerContext.RouteData.Values["action"].ToString();
            DARModel objDAR = null;

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

                if (UserModel != null)
                {
                    UserModel.Password = (!string.IsNullOrEmpty(UserModel.Password)) ? Cryptography.GetEncryptedData(UserModel.Password, true) : UserModel.Password;
                    //if (ModelState.IsValid)
                    //{
                    if (UserModel.UserId == 0)
                    {
                        if (UserModel.ProfileImage != null)
                        {
                            string       ClImageName      = UserModel.UserId + "_" + DateTime.Now.Ticks.ToString() + "_" + UserModel.ProfileImage.FileName.ToString();
                            CommonHelper obj_CommonHelper = new CommonHelper();
                            obj_CommonHelper.UploadImage(UserModel.ProfileImage, Server.MapPath(ConfigurationManager.AppSettings["ProfilePicPath"]), ClImageName);
                            UserModel.ProfileImageFile = ClImageName;
                        }
                        UserModel.CreatedBy   = ObjLoginModel.UserId;
                        UserModel.CreatedDate = DateTime.UtcNow;
                        UserModel.IsDeleted   = false;

                        objDAR                 = new DARModel();
                        objDAR.LocationId      = UserModel.Location;
                        objDAR.UserId          = ObjLoginModel.UserId;
                        objDAR.CreatedBy       = ObjLoginModel.UserId;
                        objDAR.CreatedOn       = DateTime.UtcNow;
                        objDAR.ActivityDetails = DarMessage.NewClientCreatedDar(ObjLoginModel.Location);
                        objDAR.TaskType        = Convert.ToInt64(TaskTypeCategory.UserCreation);
                    }
                    else
                    {
                        if (UserModel.ProfileImage != null)
                        {
                            string       ClImageName      = UserModel.UserId + "_" + DateTime.Now.Ticks.ToString() + "_" + UserModel.ProfileImage.FileName.ToString();
                            CommonHelper obj_CommonHelper = new CommonHelper();
                            obj_CommonHelper.UploadImage(UserModel.ProfileImage, Server.MapPath(ConfigurationManager.AppSettings["ProfilePicPath"]), ClImageName);
                            UserModel.ProfileImageFile = ClImageName;
                        }
                        UserModel.ModifiedBy   = ObjLoginModel.UserId;
                        UserModel.ModifiedDate = DateTime.UtcNow;
                        UserModel.IsDeleted    = false;
                        if (!String.IsNullOrEmpty(UserModel.Password))
                        {
                            UserModel.Password = Cryptography.GetEncryptedData(UserModel.Password, true);
                        }

                        objDAR                 = new DARModel();
                        objDAR.LocationId      = ObjLoginModel.LocationID;
                        objDAR.UserId          = ObjLoginModel.UserId;
                        objDAR.ModifiedBy      = ObjLoginModel.UserId;
                        objDAR.ModifiedOn      = DateTime.UtcNow;
                        objDAR.ActivityDetails = DarMessage.ClientUpdatedDar(ObjLoginModel.Location);
                        objDAR.TaskType        = Convert.ToInt64(TaskTypeCategory.UserUpdate);
                    }
                    //if (Session["ImageName"] != null)
                    //{
                    //    ObjUserModel.UserModel.ProfileImage = Convert.ToString(Session["ImageName"]);
                    //}

                    //Result result = _IGlobalAdmin.SaveLocation(ObjUserModel, out locationId);
                    //if (result == Result.Completed)

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

                    if (result == Result.Completed)
                    {
                        ViewBag.Message           = CommonMessage.SaveSuccessMessage();
                        ViewBag.AlertMessageClass = ObjAlertMessageClass.Success;
                        ModelState.Clear();
                        return(View("myClient"));
                    }
                    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(View("myClient"));
                    }
                    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;
            }
            ViewBag.Country    = _ICommonMethod.GetAllcountries();
            ViewBag.UpdateMode = false;
            UserModel          = _IClientManager.GetClientById(UserModel.UserId, "GetUserByID", null, null, null, null, null);
            //ViewBag.ActionName = ActionName;
            return(View("myClient"));
        }