public JsonResult Delete(int id) { if (AuthenticationService.GetCurrentUser().User.Id == id) { var mess = string.Format(SystemMessageLookup.GetMessage("CannotDeleteYourself")); MasterFileService.ThrowCustomValidation(mess); } MasterFileService.DeleteById(id); return(Json(true, JsonRequestBehavior.AllowGet)); }
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)); }