Esempio n. 1
0
        public ActionResult Index(QRCModel ObjUserModel)
        {
            DARModel objDAR = null; long LocId = 0;
            string   ImageURL        = "";
            string   ImageUniqueName = "";

            try
            {
                eTracLoginModel ObjLoginModel = null;
                if (Session["eTrac"] != null)
                {
                    ObjLoginModel = (eTracLoginModel)(Session["eTrac"]);
                }
                if (Session["eTrac_SelectedDasboardLocationID"] != null)
                {
                    LocId = (long)Session["eTrac_SelectedDasboardLocationID"];
                }
                //if (ModelState.IsValid)
                //{
                CommonHelper       ObjCommonHelper = new CommonHelper();
                HttpPostedFileBase ProfileImage    = null;
                string             msg             = string.Empty;
                if (ObjUserModel != null && ObjUserModel.UserModel != null) //&& ObjUserModel.UserModel.UserId == 0
                {
                    objDAR            = new DARModel();
                    objDAR.LocationId = ObjLoginModel.LocationID;
                    objDAR.UserId     = ObjLoginModel.UserId;
                    objDAR.CreatedBy  = ObjLoginModel.UserId;
                    objDAR.CreatedOn  = DateTime.UtcNow;
                    objDAR.TaskType   = (long)TaskTypeCategory.UserCreation;

                    if (ObjUserModel.UserModel.ProfileImage != null)
                    {
                        ProfileImage = ObjUserModel.UserModel.ProfileImage;
                    }
                    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;
                         */
                        if (!String.IsNullOrEmpty(ObjUserModel.UserModel.Password))
                        {
                            ObjUserModel.UserModel.Password = Cryptography.GetEncryptedData(ObjUserModel.UserModel.Password, true);
                        }
                        #endregion password

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

                        objDAR.TaskType        = (long)TaskTypeCategory.UserCreation;
                        objDAR.ActivityDetails = DarMessage.NewAdministratorCreatedDar(ObjLoginModel.Location);
                    }
                    else
                    {
                        ObjUserModel.UserModel.ModifiedBy   = ObjLoginModel.UserId;
                        ObjUserModel.UserModel.ModifiedDate = DateTime.UtcNow;
                        ObjUserModel.UserModel.IsDeleted    = false;
                        if (!String.IsNullOrEmpty(ObjUserModel.UserModel.Password))
                        {
                            ObjUserModel.UserModel.Password = Cryptography.GetEncryptedData(ObjUserModel.UserModel.Password, true);
                        }
                        objDAR.TaskType        = (long)TaskTypeCategory.UserUpdate;
                        objDAR.ActivityDetails = DarMessage.AdministratorUpdatedDar(ObjLoginModel.Location);
                    }
                    if (ObjUserModel.UserModel.ProfileImage != null)
                    {
                        string       ImageName        = ObjLoginModel.UserId + "_" + DateTime.Now.Ticks.ToString() + "_" + ObjUserModel.UserModel.ProfileImage.FileName.ToString();
                        CommonHelper obj_CommonHelper = new CommonHelper();
                        obj_CommonHelper.UploadImage(ObjUserModel.UserModel.ProfileImage, Server.MapPath(ConfigurationManager.AppSettings["ProfilePicPath"]), ImageName);
                        ObjUserModel.UserModel.ProfileImageFile = ImageName;
                    }
                    if (ObjUserModel.SignatureImageBase != null)
                    {
                        string ImagePath = HttpContext.Server.MapPath(ConfigurationManager.AppSettings["UserSignature"].ToString());
                        ImageUniqueName = DateTime.Now.ToString("yyyyMMddHHmmsstt") + "UserSignature";
                        string url = HostingPrefix + ImagePath.Replace("~", "") + ImageUniqueName + ".jpg";
                        ImageURL = ImageUniqueName + ".jpg";
                        if (!Directory.Exists(ImagePath))
                        {
                            Directory.CreateDirectory(ImagePath);
                        }

                        var    ImageLocation = ImagePath + ImageURL;
                        string convert       = ObjUserModel.SignatureImageBase.Replace("data:image/png;base64,", String.Empty);
                        string RemoveSpace   = convert.Replace(" ", "+");
                        byte[] image64       = Convert.FromBase64String(RemoveSpace);
                        using (MemoryStream ms = new MemoryStream(image64))
                        {
                            using (Bitmap bm2 = new Bitmap(ms))
                            {
                                bm2.Save(ImageLocation);
                            }
                        }
                    }
                    ObjUserModel.UserModel.SignatureImageBase = ImageURL;
                    long QRCID = 0;
                    //Result result = _IClientManager.SaveClient(ObjUserModel.UserModel, out QRCID, true, objDAR);

                    Result result = Result.LoginFailed; // if LocId is null then we will consider that the session is expired.
                    if (LocId > 0)
                    {
                        result = _IClientManager.SaveClient(ObjUserModel.UserModel, out QRCID, true, objDAR, LocId, ObjLoginModel.UserId, "");
                    }
                    if (result == Result.Completed)
                    {
                        ViewBag.Message           = CommonMessage.SaveSuccessMessage();
                        ViewBag.AlertMessageClass = ObjAlertMessageClass.Success;
                        var         abc            = _ICommonMethod.GetLocationDetailsById(LocId);
                        EmailHelper objEmailHelper = new EmailHelper();
                        objEmailHelper.emailid      = ObjUserModel.UserModel.UserEmail;
                        objEmailHelper.UserName     = ObjUserModel.UserModel.AlternateEmail;
                        objEmailHelper.UserType     = ObjUserModel.UserModel.UserType;
                        objEmailHelper.FirstName    = ObjUserModel.UserModel.FirstName;
                        objEmailHelper.LastName     = ObjUserModel.UserModel.LastName;
                        objEmailHelper.Password     = Cryptography.GetDecryptedData(ObjUserModel.UserModel.Password, true);
                        objEmailHelper.LocationName = abc.LocationName;
                        objEmailHelper.LocAddress   = ObjUserModel.UserModel.Address.Address1; // here locAddress means user Address
                        objEmailHelper.MailType     = "CreateNewUser";
                        HostingPrefix = HostingPrefix + "Manager/Employee?usr="******"?usr="******"index", "GlobalAdmin");
                        ObjUserModel = _ICommonMethod.LoadInvitedUser(string.Empty);
                    }
                    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("Administrator", ObjUserModel));
        }