public ActionResult Index(int?page, string searchText, int resetTo = 0) { if (resetTo == 1) { page = 1; } var statuses = LookupHelper.GetStatuses(Request.Cookies["_culture"]); ViewBag.Status = new SelectList(statuses, "Id", "Name"); ViewBag.StatusEdit = new SelectList(statuses, "Id", "Name"); var roles = _db.AspNetRoles.ToList(); if (!searchText.IsNullOrWhiteSpace()) { roles = roles.Where(r => r.Name.Contains(searchText) || r.FriendlyName.Contains(searchText) || r.Description.Contains(searchText)).ToList(); ViewBag.searchText = searchText; } var result = roles.Select(x => new RolePermissionsViewModel { Id = int.Parse(x.Id), RoleName = x.Name, RoleFriendlyName = x.FriendlyName, RoleDescription = x.Description }); var pageSize = int.Parse(SettingHelper.GetOrCreate(Constants.SystemSettings.ControlPanelPageSize, "10").Value); var pageNumber = page ?? 1; return(View(result.OrderByDescending(r => r.Id).ToList().ToPagedList(pageNumber, pageSize))); }
public Task SendAsync(IdentityMessage message) { var smtp = new System.Net.Mail.SmtpClient(); var emailAddres = SettingHelper.GetOrCreate(Core.Constants.SystemSettings.EmailsSourceEmail, "*****@*****.**").Value; var emailAddresName = SettingHelper.GetOrCreate(Core.Constants.SystemSettings.EmailsSourceName, "Crm Test").Value; var password = SettingHelper.GetOrCreate(Core.Constants.SystemSettings.EmailsResetPassword, "Crm@123$").Value; var mail = new System.Net.Mail.MailMessage { IsBodyHtml = true, From = new System.Net.Mail.MailAddress(emailAddres, emailAddresName) }; mail.To.Add(message.Destination); mail.Subject = message.Subject; mail.Body = message.Body; smtp.Timeout = 1000; smtp.Port = int.Parse(SettingHelper.GetOrCreate(Core.Constants.SystemSettings.EmailsSmtpPort, "587").Value); smtp.Credentials = new NetworkCredential(emailAddres, password); smtp.Host = SettingHelper.GetOrCreate(Core.Constants.SystemSettings.EmailsSmtpClient, "smtp-mail.outlook.com").Value; smtp.EnableSsl = SettingHelper.GetOrCreate(Core.Constants.SystemSettings.EmailsEnableSsl, "true").Value.ToLower() == "true"; var t = Task.Run(() => smtp.SendAsync(mail, null)); return(t); // Plug in your email service here to send an email. //return Task.FromResult(0); }
public JsonResult SendSMS(string text, string mobile) { try { var smsServiceRequest = new SendSmsRequest() { Url = SettingHelper.GetOrCreate(Constants.SystemSettings.SMSApiUrl, "https://019sms.co.il/api").Value, Username = SettingHelper.GetOrCreate(Constants.SystemSettings.SMSUsername, "sectorspr").Value, Password = SettingHelper.GetOrCreate(Constants.SystemSettings.SMSPassword, "faraj123").Value, Destinations = new List<string>(), Message = string.Empty, Source = SettingHelper.GetOrCreate(Constants.SystemSettings.SMSSource, "123").Value }; var smsService = new Crm.Sms.SmsService(); smsServiceRequest.Destinations = new List<string> { mobile}; smsServiceRequest.Message = text; smsService.Execute(smsServiceRequest); TempData["SMSmessage"] = "SMS Sent Succesfully"; return Json(smsServiceRequest, JsonRequestBehavior.AllowGet); } catch(Exception ex) { LogHelper.LogException(User.Identity.Name, ex, "Error While Sending SMS to Lead (Post)"); return null; } }
// api/lookups/getsettingbyname?name=System_CRM_ForgetPasswordLink public IHttpActionResult GetSettingByName(string name) { AuthenticationHelper.ApiAuthorizationCheck(Request); try { var lang = Request?.Headers?.AcceptLanguage?.FirstOrDefault()?.Value ?? "ar"; var languageId = lang == "ar" ? (int)GeneralEnums.LanguageEnum.Arabic : (int)GeneralEnums.LanguageEnum.English; var result = new SettingViewModel(); switch (name) { case Constants.SystemSettings.ForgetPasswordLink: result = SettingHelper.GetOrCreate(name, "http://crm.smsm-it.com/Account/ForgotPassword", languageId); break; case Constants.SystemSettings.RegistrationLink: result = SettingHelper.GetOrCreate(name, "http://crm.smsm-it.com/Account/Register", languageId); break; } return(Ok(result)); } catch (Exception ex) { LogHelper.LogException(Constants.Users.Mobile, ex, Constants.Errors.Apis.ErrorGettingCustomSetting); return(Content(HttpStatusCode.InternalServerError, new BaseApiResponse() { StatusCode = HttpStatusCode.InternalServerError, Message = Constants.Errors.Apis.ErrorGettingCustomSetting })); } }
public ActionResult Index(int?page, string searchText, int resetTo = 0) { if (resetTo == 1) { page = 1; } var statuses = LookupHelper.GetStatuses(Request.Cookies["_culture"]); var languages = LookupHelper.GetLanguages(Request.Cookies["_culture"]); ViewBag.Status = new SelectList(statuses, "Id", "Name"); ViewBag.StatusEdit = new SelectList(statuses, "Id", "Name"); ViewBag.DefaultTemplateLang = new SelectList(languages, "Id", "Name"); ViewBag.DefaultTemplateLangEdit = new SelectList(languages, "Id", "Name"); var currentLanguageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]); var smsTemplatesForCurrentLan = _db.SMSTemplateTranslations .Where(r => (r.LanguageId == currentLanguageId) && r.SMSTemplate.Status != (int)GeneralEnums.StatusEnum.Deleted).Select(c => c.SMSTemplateId); var smsTemplates = _db.SMSTemplateTranslations .Where(r => (r.IsDefault) && r.SMSTemplate.Status != (int)GeneralEnums.StatusEnum.Deleted && !smsTemplatesForCurrentLan.Contains(r.SMSTemplateId)) .Union( _db.SMSTemplateTranslations .Where(r => r.LanguageId == currentLanguageId && r.SMSTemplate.Status != (int)GeneralEnums.StatusEnum.Deleted && smsTemplatesForCurrentLan.Contains(r.SMSTemplateId))) .ToList(); if (!searchText.IsNullOrWhiteSpace()) { smsTemplates = smsTemplates .Where(r => (r.Name.Contains(searchText) || r.Description.Contains(searchText))).ToList(); ViewBag.searchText = searchText; } var result = smsTemplates.ToList().Select(x => new SMSTemplateViewModel() { Id = x.SMSTemplateId, Name = x.Name, IsDefault = x.IsDefault, LanguageId = x.LanguageId, Status = x.SMSTemplate.Status, Description = x.Description, DefaultTemplateLanguage = x.SMSTemplate.DefaultLanguage, CreatedOn = x.SMSTemplate.CreatedOn, DeletedOn = x.SMSTemplate.DeletedOn, CreatedBy = x.SMSTemplate.CreatedBy, }); int pageSize = int.Parse(SettingHelper.GetOrCreate(Constants.SystemSettings.ControlPanelPageSize, "10").Value); var pageNumber = (page ?? 1); return(View(result.OrderByDescending(r => r.Id).ToList().ToPagedList(pageNumber, pageSize))); }
protected void Application_Error() { var exception = Server.GetLastError(); var httpException = exception as HttpException; Response.Clear(); Server.ClearError(); var routeData = new RouteData(); routeData.Values["controller"] = "Error"; routeData.Values["action"] = "Error"; routeData.Values["exception"] = exception; routeData.Values["errorCode"] = 500; Response.StatusCode = 500; if (httpException != null) { Response.StatusCode = httpException.GetHttpCode(); switch (Response.StatusCode) { case 403: routeData.Values["errorCode"] = 403; break; case 404: routeData.Values["errorCode"] = 404; break; default: routeData.Values["errorCode"] = Response.StatusCode; break; } try { LogHelper.AddSystemLog(new SystemLog() { Name = $"ApplicationError - {exception.Message}", Component = "ApplicationError", CreatedBy = "System", CreatedOn = DateTime.Now, StackTrace = exception.StackTrace }); } catch (Exception ex) { } } var fromAddress = SettingHelper.GetOrCreate(Constants.SystemSettings.EmailsSourceEmail, "*****@*****.**").Value; var toAddress = SettingHelper.GetOrCreate(Constants.SystemSettings.EmailsErrorEmail, "*****@*****.**").Value; new EmailHelper().SendMail(fromAddress, new List <string>() { toAddress }, "General Error", $"Message: {exception.Message}. InnerException: {exception.InnerException}. StackTrace: {exception.StackTrace}"); IController errorsController = new ErrorController(); var rc = new RequestContext(new HttpContextWrapper(Context), routeData); errorsController.Execute(rc); }
public ActionResult Index(int?page, string searchText, int resetTo = 0) { if (resetTo == 1) { page = 1; } var status = LookupHelper.GetStatuses(Request.Cookies["_culture"]); ViewBag.Status = new SelectList(status, "Id", "Name"); ViewBag.StatusEdit = new SelectList(status, "Id", "Name"); ViewBag.StatusDetails = new SelectList(status, "Id", "Name"); ViewBag.StatusEditDetails = new SelectList(status, "Id", "Name"); var currentLanguageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]); var masterLookupsForcurrentLan = _db.MasterLookupTranslations .Where(r => (r.LanguageId == currentLanguageId) && r.MasterLookup.Status != (int)GeneralEnums.StatusEnum.Deleted).Select(c => c.MasterLookupId); var masterLookup = _db.MasterLookupTranslations .Where(r => (r.IsDefault) && r.MasterLookup.Status != (int)GeneralEnums.StatusEnum.Deleted && !masterLookupsForcurrentLan.Contains(r.MasterLookupId)) .Union( _db.MasterLookupTranslations .Where(r => r.LanguageId == currentLanguageId && r.MasterLookup.Status != (int)GeneralEnums.StatusEnum.Deleted && masterLookupsForcurrentLan.Contains(r.MasterLookupId))) .ToList(); if (!string.IsNullOrWhiteSpace(searchText)) { masterLookup = masterLookup.Where(r => r.Name.Contains(searchText)).ToList(); ViewBag.searchText = searchText; } var result = masterLookup.ToList().Select(r => new MasterLookupViewModel { Id = r.MasterLookup.Id, Status = r.MasterLookup.Status, Name = r.Name, CreatedBy = r.MasterLookup.CreatedBy, CreatedOn = r.MasterLookup.CreatedOn, DeletedOn = r.MasterLookup.DeletedOn, IsDefault = r.IsDefault, LanguageId = r.LanguageId } ); var pageSize = int.Parse(SettingHelper.GetOrCreate(Constants.SystemSettings.ControlPanelPageSize, "10").Value); var pageNumber = (page ?? 1); return(View(result.OrderByDescending(r => r.Id).ToPagedList(pageNumber, pageSize))); }
public static void ApiAuthorizationCheck(HttpRequestMessage request) { var headers = request.Headers; if (headers.Authorization == null) { throw new HttpResponseException(HttpStatusCode.Unauthorized); } string authenticationString = headers.Authorization.Parameter; string originalString = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationString)); string userName = originalString.Split(':')[0]; string password = originalString.Split(':')[1]; var usernameSetting = SettingHelper.GetOrCreate(Core.Constants.SystemSettings.IntegrationApiUsername, "Integration"); var passwordSetting = SettingHelper.GetOrCreate(Core.Constants.SystemSettings.IntegrationApiPassword, "C@rm@123"); if (usernameSetting.Value != userName || passwordSetting.Value != password) { throw new HttpResponseException(HttpStatusCode.Unauthorized); } }
public static string Encrypt(string stringToEncrypt) { var inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt); byte[] rgbIv = { 0x21, 0x43, 0x56, 0x87, 0x10, 0xfd, 0xea, 0x1c }; try { var setting = SettingHelper.GetOrCreate("SystemDefaults_UrlEncryption_Password", "Fur$c@1A$D"); var key = Encoding.UTF8.GetBytes(setting.Value); var des = new DESCryptoServiceProvider(); var ms = new MemoryStream(); var cs = new CryptoStream(ms, des.CreateEncryptor(key, rgbIv), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); return(Convert.ToBase64String(ms.ToArray())); } catch (Exception e) { return(e.Message); } }
public ActionResult Index(int?page, string searchText, int resetTo = 0) { if (resetTo == 1) { page = 1; } var statuses = LookupHelper.GetStatuses(Request.Cookies["_culture"]); ViewBag.Status = new SelectList(statuses, "Id", "Name"); ViewBag.StatusEdit = new SelectList(statuses, "Id", "Name"); var permissions = _db.Permissions .Where(r => r.Status != (int)GeneralEnums.StatusEnum.Deleted); if (!searchText.IsNullOrWhiteSpace()) { permissions = permissions .Where(r => r.PageUrl.Contains(searchText) || r.PageName.Contains(searchText) || r.PermissionKey.Contains(searchText) || r.Description.Contains(searchText)); ViewBag.searchText = searchText; } var result = permissions.ToList().Select(x => new PermissionViewModel() { Id = x.Id, PageUrl = x.PageUrl, PageName = x.PageName, PermissionKey = x.PermissionKey, Status = x.Status, Description = x.Description, CreatedOn = x.CreatedOn, DeletedOn = x.DeletedOn, CreatedBy = x.CreatedBy }); int pageSize = int.Parse(SettingHelper.GetOrCreate(Constants.SystemSettings.ControlPanelPageSize, "10").Value); var pageNumber = (page ?? 1); return(View(result.OrderByDescending(r => r.Id).ToList().ToPagedList(pageNumber, pageSize))); }
public ActionResult Index(int?page, int?typeId, string searchText, int resetTo = 0) { if (resetTo == 1) { page = 1; } ViewBag.SearchText = searchText; ViewBag.TypeId = typeId; var citizens = _db.AspNetUserRoles.Where(r => r.AspNetRole.Name == Constants.Roles.Citizen) .Select(r => r.AspNetUser.UserName).ToList(); var currentLanguageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]); var userProfilesForcurrentLan = _db.UserProfileTranslations .Where(r => (r.LanguageId == currentLanguageId) && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted).Select(c => c.UserProfileId); var userProfiles = _db.UserProfileTranslations .Where(r => (r.IsDefault) && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted && !userProfilesForcurrentLan.Contains(r.UserProfileId)) .Union( _db.UserProfileTranslations .Where(r => r.LanguageId == currentLanguageId && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted && userProfilesForcurrentLan.Contains(r.UserProfileId))); userProfiles = userProfiles.Where(r => citizens.Contains(r.UserProfile.Username)); if (typeId != null) { switch (typeId) { case (int)GeneralEnums.PersonInformationTypeEnum.Name: userProfiles = userProfiles.Where(r => r.FullName.Contains(searchText)); break; case (int)GeneralEnums.PersonInformationTypeEnum.Email: userProfiles = userProfiles.Where(r => r.UserProfile.Email.Contains(searchText)); break; case (int)GeneralEnums.PersonInformationTypeEnum.Mobile: userProfiles = userProfiles.Where(r => r.UserProfile.Mobile.Contains(searchText) || r.UserProfile.PhoneNumber.Contains(searchText) || r.UserProfile.Fax.Contains(searchText)); break; case (int)GeneralEnums.PersonInformationTypeEnum.Identity: userProfiles = userProfiles.Where(r => r.UserProfile.IdNumber.Contains(searchText)); break; } } var result = userProfiles.ToList().Select(x => new ProfileViewModel() { Id = x.UserProfileId, LanguageId = x.LanguageId, IdNumber = x.UserProfile.IdNumber, PhoneNumber = x.UserProfile.PhoneNumber, GenderLookupId = x.UserProfile.GenderLookupId, MartialStatusLookupId = x.UserProfile.MartialStatusLookupId, FullName = x.FullName, Address = x.Address, Mobile = x.UserProfile.Mobile, Username = x.UserProfile.Username, Email = x.UserProfile.Email, Fax = x.UserProfile.Fax, BirthDay = x.UserProfile.Birthday, Status = x.UserProfile.Status, CityId = x.UserProfile.CityId, ProvinceId = x.UserProfile.ProvinceId, RegionId = x.UserProfile.RegionId, LastLogin = x.UserProfile.LastLogin, ManagerId = x.UserProfile.ManagerId, ManagerName = x.UserProfile?.ManagerId != null ? LanguageFallbackHelper.GetUserProfile((int)x.UserProfile.ManagerId, currentLanguageId)?.FullName : string.Empty, Department = x.UserProfile.DepartmentId, DepartmentName = x.UserProfile?.DepartmentId != null ? LanguageFallbackHelper.GetDepartment((int)x.UserProfile.DepartmentId, currentLanguageId)?.Name : string.Empty, PrefferdLanguage = x.UserProfile.PreferedLanguageId }); var pageSize = int.Parse(SettingHelper.GetOrCreate(Constants.SystemSettings.ControlPanelPageSize, "10").Value); var pageNumber = page ?? 1; return(View(result.OrderByDescending(r => r.Id).ToList().ToPagedList(pageNumber, pageSize))); }
public ActionResult Index(int? campaignNo) { var companyId = SessionHelper.GetCompanyId(); var CampaignList = _db.Campaigns.Where(r => r.CompanyId == companyId).Select(r=>r.Id).ToList(); int NewLeads; int QualifiedLeads; int WonLeads; int LostLeads; var currentLanguageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]); var LeadList = _db.Leads.Where(r=> CampaignList.Contains(r.CampaignId.Value)).ToList(); if (campaignNo != null) { LeadList = _db.Leads.Where(x => x.CampaignId == campaignNo).ToList(); } var LeadList_result = LeadList.Select(r => new LeadViewModel { Id = r.Id, Status = (LeadStatusEnum)r.Status, Email = r.Email, Name = r.Name, Address=r.Address, Phone_Number = r.Phone_Number, Notes=r.Notes, Created_Date=r.Created_Date, AssigneeId = r.AssigneeId, AssigneeName = LanguageFallbackHelper.GetUserProfile((r.UserProfile?.Id ?? 0), currentLanguageId)?.FullName, CampaignId = r.CampaignId, CampaignName=LanguageFallbackHelper.GetCampaigns(r.Campaign.Id,currentLanguageId).Name } ).ToList(); if (campaignNo != null) { NewLeads = LeadList_result.Count(r => r.Status == LeadStatusEnum.New && r.CampaignId == campaignNo); QualifiedLeads = LeadList_result.Count(r => r.Status == LeadStatusEnum.Qualified && r.CampaignId == campaignNo); WonLeads = LeadList_result.Count(r => r.Status == LeadStatusEnum.Won && r.CampaignId == campaignNo); LostLeads = LeadList_result.Count(r => r.Status == LeadStatusEnum.Lost && r.CampaignId == campaignNo); } else { NewLeads = LeadList_result.Count(r => r.Status == LeadStatusEnum.New); QualifiedLeads = LeadList_result.Count(r => r.Status == LeadStatusEnum.Qualified); WonLeads = LeadList_result.Count(r => r.Status == LeadStatusEnum.Won); LostLeads = LeadList_result.Count(r => r.Status == LeadStatusEnum.Lost); } ViewData["NewLeads"] = NewLeads; ViewData["QualifiedLeads"] = QualifiedLeads; ViewData["WonLeads"] = WonLeads; ViewData["LostLeads"] = LostLeads; var list = new List<SelectListItem> { new SelectListItem{ Text=App_GlobalResources.General.Home.Name, Value = "Name", Selected = true}, new SelectListItem{ Text=App_GlobalResources.General.Home.Email, Value = "Email" }, new SelectListItem{ Text=App_GlobalResources.General.Home.Mobile, Value = "Mobile"} }; ViewData["SearchFieldsList"] = list; var pageSize = int.Parse(SettingHelper.GetOrCreate(Constants.SystemSettings.ControlPanelPageSize, "20").Value); return View(LeadList_result); // return View(LeadList_result.OrderByDescending(r => r.Id).ToList().ToPagedList(1,pageSize)); }
public ActionResult Index(int?page, string searchText, int resetTo = 0) { if (!SessionHelper.CheckSessionCompanyId()) { //logout } var companyId = SessionHelper.GetCompanyId(); if (resetTo == 1) { page = 1; } var genders = LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.Gender, Request.Cookies["_culture"]); var prefferdLanguage = LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.PrefferdLanguage, Request.Cookies["_culture"]); var roles = _db.AspNetRoles.ToList(); var departments = LookupHelper.GetDepartments(Request.Cookies["_culture"]); var managers = LookupHelper.GetEmployees(Request.Cookies["_culture"]); var martialStatuses = LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.MartialStatus, Request.Cookies["_culture"]); var statuses = LookupHelper.GetStatuses(Request.Cookies["_culture"]); ViewBag.Status = new SelectList(statuses, "Id", "Name"); ViewBag.RoleList = new SelectList(roles, "Id", "Name"); ViewBag.DepartmentsList = new SelectList(departments, "Id", "Name"); ViewBag.DepartmentsListEdit = new SelectList(departments, "Id", "Name"); ViewBag.StatusEdit = new SelectList(statuses, "Id", "Name"); ViewBag.GenderLookupId = new SelectList(genders, "Id", "Name"); ViewBag.GenderLookupIdEdit = new SelectList(genders, "Id", "Name"); ViewBag.PrefferdLanguage = new SelectList(prefferdLanguage, "Id", "Name"); ViewBag.PrefferdLanguageEdit = new SelectList(prefferdLanguage, "Id", "Name"); ViewBag.ManagerId = new SelectList(managers, "Id", "FullName"); ViewBag.ManagerIdEdit = new SelectList(managers, "Id", "FullName"); ViewBag.MartialStatusLookupId = new SelectList(martialStatuses, "Id", "Name"); ViewBag.MartialStatusLookupIdEdit = new SelectList(martialStatuses, "Id", "Name"); var currentLanguageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]); var userProfilesForcurrentLan = _db.UserProfileTranslations .Where(r => (r.LanguageId == currentLanguageId) && r.UserProfile.CompanyId == companyId && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted).Select(c => c.UserProfileId); var userProfiles = _db.UserProfileTranslations .Where(r => (r.IsDefault) && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted && !userProfilesForcurrentLan.Contains(r.UserProfileId) && r.UserProfile.CompanyId == companyId) .Union( _db.UserProfileTranslations .Where(r => r.LanguageId == currentLanguageId && r.UserProfile.CompanyId == companyId && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted && userProfilesForcurrentLan.Contains(r.UserProfileId))) .ToList(); if (!searchText.IsNullOrWhiteSpace()) { userProfiles = userProfiles .Where(r => (r.FullName.Contains(searchText) || r.FullName.Contains(searchText) || r.UserProfile.Mobile.Contains(searchText) || r.UserProfile.PhoneNumber.Contains(searchText))).ToList(); ViewBag.searchText = searchText; } var result = userProfiles.ToList().Select(x => new ProfileViewModel() { Id = x.UserProfileId, LanguageId = x.LanguageId, IdNumber = x.UserProfile.IdNumber, PhoneNumber = x.UserProfile.PhoneNumber, GenderLookupId = x.UserProfile.GenderLookupId, MartialStatusLookupId = x.UserProfile.MartialStatusLookupId, FullName = x.FullName, Address = x.Address, Mobile = x.UserProfile.Mobile, Username = x.UserProfile.Username, Email = x.UserProfile.Email, Fax = x.UserProfile.Fax, BirthDay = x.UserProfile.Birthday, Status = x.UserProfile.Status, CityId = x.UserProfile.CityId, ProvinceId = x.UserProfile.ProvinceId, RegionId = x.UserProfile.RegionId, LastLogin = x.UserProfile.LastLogin, ManagerId = x.UserProfile.ManagerId, ManagerName = x.UserProfile?.ManagerId != null ? LanguageFallbackHelper.GetUserProfile((int)x.UserProfile.ManagerId, currentLanguageId)?.FullName : string.Empty, Department = x.UserProfile.DepartmentId, DepartmentName = x.UserProfile?.DepartmentId != null ? LanguageFallbackHelper.GetDepartment((int)x.UserProfile.DepartmentId, currentLanguageId)?.Name : string.Empty, PrefferdLanguage = x.UserProfile.PreferedLanguageId, CompanyId = x.UserProfile.CompanyId, }); int pageSize = int.Parse(SettingHelper.GetOrCreate(Core.Constants.SystemSettings.ControlPanelPageSize, "10").Value); var pageNumber = (page ?? 1); return(View(result.OrderByDescending(r => r.Id).ToList().ToPagedList(pageNumber, pageSize))); }
public IHttpActionResult Login(string username, string password) { AuthenticationHelper.ApiAuthorizationCheck(Request); try { var lang = Request?.Headers?.AcceptLanguage?.FirstOrDefault()?.Value ?? "ar"; var langId = lang == "ar" ? (int)GeneralEnums.LanguageEnum.Arabic : (int)GeneralEnums.LanguageEnum.English; var user = UserManager.FindByName(username); var isAllowed = SignInManager.UserManager.CheckPassword(user, password); var roles = _db.AspNetUserRoles.Where(r => r.UserId == user.Id).ToList().Select(r => new RoleViewModel() { Name = r.AspNetRole.Name, RoleId = r.RoleId }).ToList(); var allowedRoles = SettingHelper.GetOrCreate(Core.Constants.SystemSettings.AllowedRolesForMobile, "Administrator,citizen,User").Value.Split(','); var hasValidRole = roles.Any(r => allowedRoles.Contains(r.Name)); if (isAllowed && hasValidRole) { var profile = _db.UserProfileTranslations.FirstOrDefault(r => r.UserProfile.Username == username && r.LanguageId == langId); if (profile == null) { profile = _db.UserProfileTranslations.FirstOrDefault(r => r.UserProfile.Username == username && r.IsDefault); } var result = new ProfileViewModel() { Id = profile.UserProfileId, LanguageId = profile.LanguageId, IdNumber = profile.UserProfile.IdNumber ?? string.Empty, PhoneNumber = profile.UserProfile.PhoneNumber ?? string.Empty, GenderLookupId = profile.UserProfile.GenderLookupId, ProvinceId = profile.UserProfile.ProvinceId, CityId = profile.UserProfile.CityId, RegionId = profile.UserProfile.RegionId, MartialStatusLookupId = profile.UserProfile.MartialStatusLookupId, PrefferdLanguage = profile.UserProfile.PreferedLanguageId, Department = profile.UserProfile.DepartmentId, ManagerId = profile.UserProfile.ManagerId, FullName = profile.FullName, Mobile = profile.UserProfile.Mobile ?? string.Empty, Address = profile.Address ?? string.Empty, Email = profile.UserProfile.Email, Username = profile.UserProfile.Username, Fax = profile.UserProfile.Fax ?? string.Empty, BirthDay = profile.UserProfile.Birthday, ProfilePath = profile.UserProfile.ProfilePhoto, Roles = roles }; return(Ok(result)); } else { return(Content(HttpStatusCode.Forbidden, new BaseApiResponse() { StatusCode = HttpStatusCode.Forbidden, Message = Core.Constants.Errors.Apis.ErrorLoginNoAccess })); } } catch (Exception ex) { LogHelper.LogException(Core.Constants.Users.Mobile, ex, Core.Constants.Errors.Apis.ErrorLogin); return(Content(HttpStatusCode.InternalServerError, new BaseApiResponse() { StatusCode = HttpStatusCode.InternalServerError, Message = Core.Constants.Errors.Apis.ErrorLogin })); } }
public async Task <IHttpActionResult> UploadFile(int id) { if (!Request.Content.IsMimeMultipartContent()) { return(Content(HttpStatusCode.UnsupportedMediaType, new BaseApiResponse() { StatusCode = HttpStatusCode.UnsupportedMediaType, Message = Constants.ApiMessages.UnSupported })); } try { var provider = new MultipartMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); var sysFiles = new List <FileResponse>(); foreach (var file in provider.Contents) { var dataStream = await file.ReadAsByteArrayAsync(); var sysFile = new SystemFile { CreatedBy = User.Identity.Name, CreatedOn = DateTime.Now, Status = (int)GeneralEnums.StatusEnum.Active, TypeId = id, FileUrl = string.Empty, ModifiedBy = User.Identity.Name, ModifiedOn = DateTime.Now }; _db.SystemFiles.Add(sysFile); _db.SaveChanges(); var extention = Path.GetExtension(file.Headers.ContentDisposition.FileName.Trim('"').Trim('/')); File.WriteAllBytes( HttpContext.Current.Server.MapPath($"~/Document/{id}/{sysFile.Id}{extention}"), dataStream); var setting = SettingHelper.GetOrCreate(Constants.SystemSettings.WebsiteUrl, "http://localhost:61712/"); var url = $"{setting.Value}/Document/{id}/{sysFile.Id}{extention}"; sysFiles.Add(new FileResponse() { Id = sysFile.Id, CreatedOn = sysFile.CreatedOn, TypeId = sysFile.TypeId, FileUrl = url, StatusCode = HttpStatusCode.OK, Message = Constants.ApiMessages.Success }); sysFile.FileUrl = url; _db.Entry(sysFile).State = EntityState.Modified; _db.SaveChanges(); var sysFileTrans = new SystemFileTranslation() { Description = string.Empty, DisplayName = string.Empty, IsDefault = true, LanguageId = CultureHelper.GetDefaultLanguageId(), SystemFileId = sysFile.Id }; _db.SystemFileTranslations.Add(sysFileTrans); _db.SaveChanges(); } return(Ok(sysFiles)); } catch (Exception ex) { LogHelper.LogException(User.Identity.Name, ex, "Error While uploading file!"); return(Content(HttpStatusCode.InternalServerError, new BaseApiResponse() { StatusCode = HttpStatusCode.InternalServerError, Message = Constants.ApiMessages.GeneralError })); } }