예제 #1
0
        public JsonResult Create(CourierParameter parameters)
        {
            //get franchisee configuration
            var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
            var objFranchiseeAndLicense = new FranchisseNameAndLicenseDto
            {
                FranchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "",
                LicenseKey     = franchiseeConfiguration != null ? franchiseeConfiguration.LicenseKey : ""
            };
            var packageInfo    = _webApiConsumeUserService.GetListPackageChange(objFranchiseeAndLicense);
            var currentPackage = packageInfo.OrderByDescending(o => o.Id).Where(o => o.IsApply).FirstOrDefault();

            //Lay so luong courier dc cho phep cua franchisee
            int numberAllow = 2;

            if (currentPackage != null)
            {
                numberAllow = CaculatorHelper.GetNumberUserAllow(currentPackage.PackageId);
            }

            var numberOfUserCurrent = _userService.Count(o => o.UserRoleId == 2);

            if (numberAllow <= numberOfUserCurrent)
            {
                var mess = string.Format(SystemMessageLookup.GetMessage("NumberUserAllow"));
                MasterFileService.ThrowCustomValidation(mess);
            }
            //Bat dau Add
            var viewModel = MapFromClientParameters(parameters);
            var entity    = viewModel.MapTo <Courier>();

            entity.Status = (int)StatusCourier.Offline;
            // Generate password
            const string randomPassword = "******";

            if (entity.User.UserName != null)
            {
                entity.User.Password = PasswordHelper.HashString(randomPassword, entity.User.UserName);
            }

            var sharViewModel = viewModel.SharedViewModel as DashboardCourierShareViewModel;//
            var logoFilePath  = "";

            if (sharViewModel != null)
            {
                if (!String.IsNullOrEmpty(sharViewModel.UserShareViewModel.Avatar))
                {
                    if (!sharViewModel.UserShareViewModel.Avatar.Contains("data:image/jpg;base64"))
                    {
                        logoFilePath       = Server.MapPath(sharViewModel.UserShareViewModel.Avatar);
                        entity.User.Avatar = _resizeImage.ResizeImageByHeightAndWidth(logoFilePath, 450, 450);
                    }
                }
            }



            var savedEntity = MasterFileService.Add(entity);

            if (savedEntity.Id > 0)
            {
                var webLink       = AppSettingsReader.GetValue("Url", typeof(String)) as string;
                var imgSrc        = webLink + "/Content/quickspatch/img/logo-o.svg";
                var urlChangePass = webLink + "/Authentication/ChangePasswordCourier?code=" + PasswordHelper.HashString(savedEntity.Id.ToString(), entity.User.UserName);
                var fromEmail     = AppSettingsReader.GetValue("EmailFrom", typeof(String)) as string;
                var webapi        = AppSettingsReader.GetValue("WebApiUrlFranchisee", typeof(String)) as string;
                var displayName   = AppSettingsReader.GetValue("EmailFromDisplayName", typeof(String)) as string;
                //var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
                var franchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "";
                var emailContent   = Framework.Utility.TemplateHelpper.FormatTemplateWithContentTemplate(
                    TemplateHelpper.ReadContentFromFile(TemplateConfigFile.CreateCourierEmailTemplate, true),
                    new
                {
                    img_src         = imgSrc,
                    full_name       = Framework.Utility.CaculatorHelper.GetFullName(savedEntity.User.FirstName, savedEntity.User.MiddleName, savedEntity.User.LastName),
                    web_link        = webLink,
                    user_name       = entity.User.UserName,
                    password        = randomPassword,
                    url_change_pass = urlChangePass,
                    franchisee_Name = franchiseeName,
                    web_api         = webapi
                });
                // send email
                var logo = franchiseeConfiguration != null ? franchiseeConfiguration.Logo : new byte[0];
                _emailHandler.SendEmailSsl(fromEmail, new[] { savedEntity.User.Email }, SystemMessageLookup.GetMessage("SubjectToSendEmailForCreateUser"),
                                           emailContent, logo, true, displayName);
            }
            return
                (Json(new
            {
                id = savedEntity.Id,
                name =
                    Framework.Utility.CaculatorHelper.GetFullName(savedEntity.User.FirstName,
                                                                  savedEntity.User.MiddleName, savedEntity.User.LastName)
            }, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public int Create(UserParameter parameters)
        {
            //get franchisee configuration
            var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
            var objFranchiseeAndLicense = new FranchisseNameAndLicenseDto
            {
                FranchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "",
                LicenseKey     = franchiseeConfiguration != null ? franchiseeConfiguration.LicenseKey : ""
            };
            var packageInfo = _webApiConsumeUserService.GetListPackageChange(objFranchiseeAndLicense);

            //Bat dau Add
            var viewModel = MapFromClientParameters(parameters);
            var entity    = viewModel.MapTo <User>();
            // Generate password
            const string randomPassword = "******";

            if (entity.UserName != null)
            {
                entity.Password = PasswordHelper.HashString(randomPassword, entity.UserName);
            }
            //entity.Password = "******";
            var sharViewModel = viewModel.SharedViewModel as DashboardUserShareViewModel;//
            var logoFilePath  = "";

            if (sharViewModel != null)
            {
                if (!String.IsNullOrEmpty(sharViewModel.Avatar))
                {
                    if (!sharViewModel.Avatar.Contains("data:image/jpg;base64"))
                    {
                        logoFilePath  = Server.MapPath(sharViewModel.Avatar);
                        entity.Avatar = _resizeImage.ResizeImageByHeightAndWidth(logoFilePath, 450, 450);
                    }
                }
            }


            var savedEntity = MasterFileService.Add(entity);

            if (savedEntity.Id > 0)
            {
                var webLink       = AppSettingsReader.GetValue("Url", typeof(String)) as string;
                var urlSignIn     = webLink + "/Authentication/SignIn";
                var imgSrc        = webLink + "/Content/quickspatch/img/logo-o.svg";
                var urlChangePass = webLink + "/Authentication/ChangePassword?code=" + PasswordHelper.HashString(savedEntity.Id.ToString(), entity.UserName);
                var fromEmail     = AppSettingsReader.GetValue("EmailFrom", typeof(String)) as string;
                var displayName   = AppSettingsReader.GetValue("EmailFromDisplayName", typeof(String)) as string;
                //var franchiseeConfiguration = _franchiseeConfigurationService.GetFranchiseeConfiguration();
                var franchiseeName = franchiseeConfiguration != null ? franchiseeConfiguration.Name : "";
                var emailContent   = Framework.Utility.TemplateHelpper.FormatTemplateWithContentTemplate(
                    TemplateHelpper.ReadContentFromFile(TemplateConfigFile.CreateUserEmailTemplate, true),
                    new
                {
                    img_src         = imgSrc,
                    full_name       = Framework.Utility.CaculatorHelper.GetFullName(savedEntity.FirstName, savedEntity.MiddleName, savedEntity.LastName),
                    web_link        = webLink,
                    user_name       = entity.UserName,
                    password        = randomPassword,
                    url_change_pass = urlChangePass,
                    franchisee_Name = franchiseeName,
                    url_sign_in     = urlSignIn
                });
                // send email
                var logo = franchiseeConfiguration != null ? franchiseeConfiguration.Logo : new byte[0];
                _emailHandler.SendEmailSsl(fromEmail, new[] { savedEntity.Email }, SystemMessageLookup.GetMessage("SubjectToSendEmailForCreateUser"),
                                           emailContent, logo, true, displayName);
            }
            return(savedEntity.Id);
        }