// GET: /Account/Index public async Task <ActionResult> Index(ManageMessageId?message) { //var userid = await UserManager.FindByIdAsync(User.Identity.GetUserId<int>()); //ViewBag.CurrentUserName = userid.FirstName; var user = new RepositoryUserProfile().GetUserbyId(User.Identity.GetUserId <int>()); ViewBag.businessName = user.BusinessName; ViewBag.RelativeUrl = user.RelativeUrl; ViewBag.Logo = "/Assets/" + user.BusinessId + "/Logo_" + user.BusinessId + ".jpg"; ViewBag.CurrentUserName = user.FirstName; ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set." : message == ManageMessageId.Error ? "An error has occurred." : ""; var model = new IndexViewModel { HasPassword = HasPassword(), PhoneNumber = await UserManager.GetPhoneNumberAsync(User.Identity.GetUserId <int>()), TwoFactor = await UserManager.GetTwoFactorEnabledAsync(User.Identity.GetUserId <int>()), Logins = await UserManager.GetLoginsAsync(User.Identity.GetUserId <int>()), BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(User.Identity.GetUserId <int>().ToString()) }; return(View(model)); }
private void NewAccountEmailNotification(EmailNotification objEmailNotify) { try { var mail = new GMEmail(); string managerEmailBody = string.Empty; //email to manager { if (objEmailNotify.Managers != null && objEmailNotify.Managers.Count() > 0) { foreach (var item in objEmailNotify.Managers) { if (CurrentUser.Email != item.Email) { string toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "ACCNFN"); if (!string.IsNullOrEmpty(toEmails)) { managerEmailBody = TemplateManager.NewPracticeToManager(objEmailNotify.RootPath, objEmailNotify.Services, objEmailNotify.Providers, objEmailNotify.PracticeAddress, item.Name, objEmailNotify.RepName, objEmailNotify.CreatedByName, objEmailNotify.PracticeName, objEmailNotify.ReturnUrl, NotificationTargetType.Account, CurrentBusinessId.Value, CurrentUser.RelativeUrl); mail.SendDynamicHTMLEmail(toEmails, "New Account Created", managerEmailBody, CurrentUser.OtherEmails); } } } } } //email to Rep { if (CurrentUser.Email != objEmailNotify.RepEmail) { string toEmails = new RepositoryUserProfile().NotificationEnabledEmails(objEmailNotify.RepEmail, "ACCNFN"); if (!string.IsNullOrEmpty(toEmails)) { var emailBody = TemplateManager.NewPracticeToRep(objEmailNotify.RootPath, objEmailNotify.Services, objEmailNotify.Providers, objEmailNotify.PracticeAddress, objEmailNotify.RepName, objEmailNotify.CreatedByName, objEmailNotify.PracticeName, objEmailNotify.ReturnUrl, NotificationTargetType.Account, CurrentBusinessId.Value, CurrentUser.RelativeUrl); mail.SendDynamicHTMLEmail(toEmails, "New Account Assigned to You", emailBody, CurrentUser.OtherEmails); } } } if (CurrentBusinessId == 1) { var addressEmailBody = TemplateManager.NewAccountAddress(objEmailNotify.RootPath, objEmailNotify.Services, objEmailNotify.Providers, objEmailNotify.PracticeAddress, objEmailNotify.CreatedByName, objEmailNotify.PracticeName, objEmailNotify.RepName, CurrentBusinessId.Value, CurrentUser.RelativeUrl); string addressNotification = ConfigurationManager.AppSettings["AddressNotification"]; string[] AddressNotification = !string.IsNullOrEmpty(addressNotification) ? addressNotification.Split(',') : null; if (AddressNotification != null && AddressNotification.Count() > 0) { foreach (var item in AddressNotification) { mail.SendDynamicHTMLEmail(item, "New Location Added", addressEmailBody, CurrentUser.OtherEmails); } } } } catch (Exception ex) { ex.Log(); } }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var isAuthorized = base.AuthorizeCore(httpContext); if (!isAuthorized) { return(false); } UserDetailsModel userModel = null; if (httpContext.Session["currentUserModel"] != null) { userModel = (UserDetailsModel)httpContext.Session["currentUserModel"]; } else { var db = new CareConnectCrmEntities(); var currentUserId = httpContext.User.Identity.GetUserId <int>(); var query = db.Users.Where(a => a.Id == currentUserId); userModel = query .Select(currentUser => new UserDetailsModel { Id = currentUser.Id, FirstName = currentUser.FirstName, MiddleName = currentUser.MiddleName, LastName = currentUser.LastName, BusinessId = currentUser.BusinessId, Email = currentUser.Email, PhoneNumber = currentUser.PhoneNumber, UserName = currentUser.UserName, BusinessName = currentUser.BusinessMaster.BusinessName, RelativeUrl = currentUser.BusinessMaster.RelativeUrl, OtherEmails = currentUser.BusinessMaster.OtherEmails, IRoles = currentUser.Roles, IDepartments = currentUser.UserDepartments }).FirstOrDefault(); var profileRepository = new RepositoryUserProfile(); userModel.UserPrivileges = profileRepository.GetUserPrivilages(userModel.Id); httpContext.Session["currentUserModel"] = userModel; } if (userModel.BusinessId == null || userModel.BusinessId == 0) { httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName; return(false); } httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName; return(true); }
private JObject GenerateLocalAccessTokenResponse(GMUser user, dynamic userDetails = null) { var BusinessDetails = new RepositoryUserProfile().GetBusinessbyId((int)user.BusinessId); var userName = user.UserName; var FullName = user.FirstName + "" + user.LastName; var UserPrivilages = new RepositoryUserProfile().GetUserPrivilages(user.Id) ?? new string[] { }; var UserRoles = new RepositoryUserProfile().GetAllUserRoles(user.Id).Model.ToNameArray(); var UserDepartments = new RepositoryUserProfile().GetAllUserDepartments(user.Id).Model.ToNameArray(); var Business = BusinessDetails.BusinessName; var DomainUrl = BusinessDetails.DomainUrl; var RelativeUrl = BusinessDetails.RelativeUrl; var UserId = user.Id; var ProfileImageUrl = string.Format("{0}/{1}/{2}/{3}/{4}.jpg", ConfigurationManager.AppSettings["PortalUrl"] ?? "", "Assets", user.BusinessId.HasValue ? user.BusinessId.ToString() : "0", "Users", user.Id.ToString());; var IsRep = userDetails != null ? userDetails.IsRep : false; var tokenExpiration = TimeSpan.FromDays(1); ClaimsIdentity identity = new ClaimsIdentity(OAuthDefaults.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, userName)); identity.AddClaim(new Claim("role", "user")); var props = new AuthenticationProperties() { IssuedUtc = DateTime.UtcNow, ExpiresUtc = DateTime.UtcNow.Add(tokenExpiration), }; var ticket = new AuthenticationTicket(identity, props); var accessToken = Startup.OAuthOptions.AccessTokenFormat.Protect(ticket); JObject tokenResponse = new JObject( //new JProperty("UserId", UserId), new JProperty("FullName", FullName), new JProperty("UserName", userName), new JProperty("Business", Business), new JProperty("DomainUrl", DomainUrl), new JProperty("IsRep", IsRep), new JProperty("RelativeUrl", RelativeUrl), new JProperty("ProfileImageUrl", ProfileImageUrl), new JProperty("UserPrivilages", UserPrivilages), new JProperty("UserRoles", UserRoles), new JProperty("UserDepartments", UserDepartments), new JProperty("AccessToken", accessToken), new JProperty("TokenType", "bearer"), new JProperty("ExpiresIn", tokenExpiration.TotalSeconds.ToString()), new JProperty("IssuedDate", ticket.Properties.IssuedUtc.ToString()), new JProperty("ExpiresOn", ticket.Properties.ExpiresUtc.ToString()), new JProperty("IsProfileFilled", !string.IsNullOrEmpty(user.Email))); return(tokenResponse); }
public IHttpActionResult GetAllNotifications() { if (!User.Identity.IsAuthenticated) { return(Ok <dynamic>(new { IsSuccess = 0, Status = HttpStatusCode.BadRequest, Model = new { }, Message = "Authorization failed!" })); } var repository = new RepositoryNotification(); var user = new RepositoryUserProfile().GetUserbyId(CurrentUserId); var response = repository.GetAllNotificationSettings(CurrentUserId); return(Ok <DataResponse>(response)); }
public IHttpActionResult GetPermissionsByUserId() { if (!User.Identity.IsAuthenticated) { return(Ok <dynamic>(new { IsSuccess = 0, Status = HttpStatusCode.BadRequest, Message = "Authorization failed!" })); } var UserPrivilages = new RepositoryUserProfile().GetUserPrivilages(CurrentUserId) ?? new string[] { }; if (UserPrivilages != null) { return(Ok <dynamic>(new { IsSuccess = 0, Message = "Success", Status = 200, Model = UserPrivilages })); } return(Ok <dynamic>(new { IsSuccess = 1, Message = "No Permission Assigned", Status = HttpStatusCode.BadRequest, Model = new { } })); }
// // GET: /Manage/ChangePassword public ActionResult ChangePassword() { var user = new RepositoryUserProfile().GetUserbyId(User.Identity.GetUserId <int>()); //ViewBag.businessName = user.BusinessName; //ViewBag.Logo = "/Assets/" + user.BusinessId + "/Logo_" + user.BusinessId + ".jpg"; var BusinessName = user.BusinessName; var RelativeUrl = user.RelativeUrl; var Logo = "/Assets/" + user.BusinessId + "/Logo_" + user.BusinessId + ".jpg"; ViewBag.CurrentUserName = user.FirstName; return(View(new ChangePasswordModel { BusinessName = BusinessName, Logo = Logo, RelativeUrl = RelativeUrl })); }
public IHttpActionResult GetUserById(int UserId) { var response = new DataResponse <EntityUser>(); var repository = new RepositoryUserProfile(); if (UserId != null) { response = repository.GetCurrentUserbyId(UserId); } else { response.Model = new EntityUser(); } return(Ok <DataResponse>(response)); }
// GET: Business/NotificationSettings public ActionResult Index() { var model = new NotificationsettingModel(); var user = new RepositoryUserProfile().GetUserbyId(CurrentUserId); model.Name = user.FirstName + " " + user.LastName; model.Notifications = from p in db.LookupNotificationTypes join ap in db.UserNotificationMappers.Where(e => e.UserId == CurrentUserId) on p.Id equals ap.NotificationTypeId into joined from j in joined.DefaultIfEmpty() select new NotificationModel { NotificationTypeId = p.Id, NotificationType = p.Title, Status = j.Status == null ? true : j.Status }; return(View(model)); }
private void NewLeadEmailNotification(EmailNotification objEmailNotify) { try { var mail = new GMEmail(); //email to manager { if (objEmailNotify.Managers != null && objEmailNotify.Managers.Count() > 0) { foreach (var item in objEmailNotify.Managers) { if (CurrentUser.Email != item.Email) { string toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "LDNFN"); if (!string.IsNullOrEmpty(toEmails)) { string emailBody = TemplateManager.NewPracticeToManager(objEmailNotify.RootPath, objEmailNotify.Services, objEmailNotify.Providers, objEmailNotify.PracticeAddress, item.Name, objEmailNotify.RepName, objEmailNotify.CreatedByName, objEmailNotify.PracticeName, objEmailNotify.ReturnUrl, NotificationTargetType.Lead, CurrentBusinessId.Value, CurrentUser.RelativeUrl); mail.SendDynamicHTMLEmail(toEmails, "New Lead Created", emailBody, CurrentUser.OtherEmails); } } } } } //email to Rep { if (CurrentUser.Email != objEmailNotify.RepEmail) { string toEmails = new RepositoryUserProfile().NotificationEnabledEmails(objEmailNotify.RepEmail, "LDNFN"); if (!string.IsNullOrEmpty(toEmails)) { string emailBody = TemplateManager.NewPracticeToRep(objEmailNotify.RootPath, objEmailNotify.Services, objEmailNotify.Providers, objEmailNotify.PracticeAddress, objEmailNotify.RepName, objEmailNotify.CreatedByName, objEmailNotify.PracticeName, objEmailNotify.ReturnUrl, NotificationTargetType.Lead, CurrentBusinessId.Value, CurrentUser.RelativeUrl); mail.SendDynamicHTMLEmail(toEmails, "New Lead Assigned to You", emailBody, CurrentUser.OtherEmails); } } } } catch (Exception ex) { ex.Log(); } }
// GET: NotificationSettings public ActionResult Index() { var currentUserId = User.Identity.GetUserId <int>(); var model = new NotificationsettingModel(); var user = new RepositoryUserProfile().GetUserbyId(currentUserId); ViewBag.businessName = user.BusinessName; ViewBag.RelativeUrl = user.RelativeUrl; ViewBag.Logo = "/Assets/" + user.BusinessId + "/Logo_" + user.BusinessId + ".jpg"; model.Name = user.FirstName + " " + user.LastName; model.Notifications = from p in db.LookupNotificationTypes join ap in db.UserNotificationMappers.Where(e => e.UserId == currentUserId) on p.Id equals ap.NotificationTypeId into joined from j in joined.DefaultIfEmpty() select new NotificationModel { NotificationTypeId = p.Id, NotificationType = p.Title, Status = j.Status == null ? true : j.Status }; return(View(model)); }
public IHttpActionResult InsertUserData(EntityUser model) { model.IsApiCall = true; var response = new DataResponse <EntityUser>(); if (ModelState.IsValid) { model.BusinessId = CurrentBusinessId; model.Id = CurrentUserId; response = new RepositoryUserProfile().Update(model); #region Upload file if (model.Files != null && model.Files.Count > 0) { List <string> FilesList = new List <string>(); int UserId = response.Model.Id; foreach (var file in model.Files) { var fileName = CurrentUserId + ".jpg"; string FileName = SaveFile(file.Base64, fileName, UserId); FilesList.Add(FileName); } //bool isImagesSaved = new RepositoryMarketing().SaveFiles(FilesList, MarketingId, model.Id > 0, CurrentUserId); } #endregion return(Ok <DataResponse>(response)); } else { var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new { Key = s.Key.Split('.').Last(), Message = s.Value.Errors[0].ErrorMessage }); return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList })); } }
public async Task <IHttpActionResult> ObtainBearerTokenCookie(string userName) { GMUser user = null; var db = new CareConnectCrmEntities(); // var currentUserId = httpContext.User.Identity.GetUserId<int>(); var query = db.Users.Where(a => a.UserName == userName); var userDetails = query.Select(a => new { Id = a.Id, BusinessId = a.BusinessId, FirstName = a.FirstName, MiddleName = a.MiddleName, LastName = a.LastName, UserName = a.UserName, PhoneNumber = a.PhoneNumber, Roles = a.Roles.Select(r => r.Name), UserDepartments = a.Departments.Select(d => d.DepartmentName), IsRep = a.Reps.Any(), BusinessName = a.BusinessMaster.BusinessName, DomainUrl = a.BusinessMaster.DomainUrl, RelativeUrl = a.BusinessMaster.RelativeUrl }).FirstOrDefault(); user = new GMUser { Id = userDetails.Id, BusinessId = userDetails.BusinessId, FirstName = userDetails.FirstName, MiddleName = userDetails.MiddleName, LastName = userDetails.LastName, UserName = userDetails.UserName, PhoneNumber = userDetails.PhoneNumber, }; bool hasRegistered = user != null; if (!hasRegistered) { return(Ok <dynamic>(new { IsSuccess = 0, Status = HttpStatusCode.BadRequest, Message = "User is not registered!", Model = new { } })); } IPrincipal genericPrincipal = new GenericPrincipal(new GenericIdentity(userName), null); ActionContext.RequestContext.Principal = genericPrincipal; var FirstName = user.FirstName; var MiddleName = user.MiddleName; var LastName = user.LastName; var PhoneNumber = user.PhoneNumber; var UserPrivilages = new RepositoryUserProfile().GetUserPrivilages(user.Id) ?? new string[] { }; var UserRoles = userDetails.Roles.ToArray(); var UserDepartments = userDetails.UserDepartments.ToArray(); var Business = userDetails.BusinessName; var DomainUrl = userDetails.DomainUrl; var RelativeUrl = userDetails.RelativeUrl; var IsRep = userDetails != null ? userDetails.IsRep : false; //------------------------------------------------------------------------------------------------------------------------------------------------------------------- var tokenExpiration = TimeSpan.FromDays(1); ClaimsIdentity identity = new ClaimsIdentity(OAuthDefaults.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, userName)); identity.AddClaim(new Claim("role", "user")); var props = new AuthenticationProperties() { IssuedUtc = DateTime.UtcNow, ExpiresUtc = DateTime.UtcNow.Add(tokenExpiration), }; var ticket = new AuthenticationTicket(identity, props); var accessToken = Startup.OAuthOptions.AccessTokenFormat.Protect(ticket); var entityUser = new EntityUser(); entityUser.Id = CurrentUserId; entityUser.FirstName = user.FirstName; entityUser.LastName = user.LastName; entityUser.BusinessId = CurrentBusinessId; JObject tokenResponse = new JObject( new JProperty("FullName", entityUser.FullName), new JProperty("UserName", userName), new JProperty("FirstName", FirstName), new JProperty("MiddleName", MiddleName), new JProperty("LastName", LastName), new JProperty("PhoneNumber", PhoneNumber), new JProperty("FilePath", entityUser.FilePath), new JProperty("Business", Business), new JProperty("DomainUrl", DomainUrl), new JProperty("IsRep", IsRep), new JProperty("RelativeUrl", RelativeUrl), new JProperty("UserPrivilages", UserPrivilages), new JProperty("UserRoles", UserRoles), new JProperty("UserDepartments", UserDepartments), new JProperty("AccessToken", accessToken), new JProperty("TokenType", "bearer"), new JProperty("ExpiresIn", tokenExpiration.TotalSeconds.ToString()), new JProperty("IssuedDate", ticket.Properties.IssuedUtc.ToString()), new JProperty("ExpiresOn", ticket.Properties.ExpiresUtc.ToString()), new JProperty("IsProfileFilled", !string.IsNullOrEmpty(user.Email))); //------------------------------------------------------------------------------------------------------------------------------------------------------------------- //generate access token response // var accessTokenResponse = GenerateLocalAccessTokenResponse(user, userDetails); //var Db = new EmegenexBiz2016Entities(); return(Ok <dynamic>(new { IsSuccess = 1, Status = 200, Model = tokenResponse, Message = "Success!" })); }
public IHttpActionResult InsertTaskData(EntityTask model) { var response = new DataResponse <EntityTask>(); var TaskId = 0; if (ModelState.IsValid) { model.UpdatedBy = model.CreatedBy = model.CurrentUserId = CurrentUserId; model.CurrentBusinessId = CurrentBusinessId; model.CreatedByName = string.Format("{0} {1}", CurrentUser.FirstName, CurrentUser.LastName); if (model.TaskId > 0) { var updateResponse = new RepositoryTask().Update(model); if (updateResponse.Status == DataResponseStatus.OK) { TaskId = (int)updateResponse.Id; } } else { response = new RepositoryTask().Insert(model); TaskId = response.Model.TaskId; #region Send email to users in assigned to and watchers list try { var rootPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath; var ReturnUrl = ConfigurationManager.AppSettings["PortalUrl"] + CurrentUser.BusinessName.Replace(" ", "-") + "#/tasks/" + response.Model.ReferenceNumber; var Subject = "Task " + response.Model.ReferenceNumber + " - " + response.Model.Subject + ""; var mail = new GMEmail(); string toEmails = null, practiceName = null, priorityType = null, targetDate = null; if (model.PracticeId.HasValue) { practiceName = new RepositoryLookups().GetPracticeNameById(model.PracticeId.Value); } if (model.PriorityTypeId.HasValue) { priorityType = EnumHelper.GetEnumName <TaskPriorities>(model.PriorityTypeId.Value); } targetDate = model.TargetDate.HasValue ? model.TargetDate.ToString() : "Not Set"; foreach (var item in response.Model.AssignedUsersList) { if (item.UserId == CurrentUserId) { continue; } var emailBody = TemplateManager.NewTask(rootPath, item.Name, "", model.CreatedByName, model.Subject, targetDate, model.TaskDescription, practiceName, priorityType, ReturnUrl, false, CurrentBusinessId.Value, CurrentUser.RelativeUrl); try { toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKASSGN"); if (!string.IsNullOrEmpty(toEmails)) { mail.SendDynamicHTMLEmail(item.Email, Subject, emailBody, CurrentUser.OtherEmails); } } catch (Exception ex) { ex.Log(); } } foreach (var item in response.Model.WatchersList) { if (item.UserId == CurrentUserId) { continue; } var AssignedUsers = string.Join(",", response.Model.AssignedUsersList.Select(a => a.Name)); var emailBody = TemplateManager.NewTask(rootPath, item.Name, AssignedUsers, model.CreatedByName, model.Subject, targetDate, model.TaskDescription, practiceName, priorityType, ReturnUrl, true, CurrentBusinessId.Value, CurrentUser.RelativeUrl); try { toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKCC"); if (!string.IsNullOrEmpty(toEmails)) { mail.SendDynamicHTMLEmail(item.Email, Subject, emailBody, CurrentUser.OtherEmails); } } catch (Exception ex) { ex.Log(); } } } catch (Exception ex) { ex.Log(); } #endregion } #region Upload file if (model.Files != null && model.Files.Count > 0) { List <string> FilesList = new List <string>(); foreach (var file in model.Files) { string FileName = SaveFile(file.Base64, file.FileName, TaskId); FilesList.Add(FileName); } bool isImagesSaved = new RepositoryTask().SaveFiles(FilesList, TaskId, model.TaskId > 0); } #endregion response = new RepositoryTask().GetTaskById(TaskId, CurrentUserId, CurrentBusinessId, true); return(Ok <DataResponse>(response)); } else { var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new { Key = s.Key.Split('.').Last(), Message = s.Value.Errors[0].ErrorMessage }); return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList })); } }
private void SendEmailNotification(string returnUrl, int taskId) { var repository = new RepositoryTask(); var objTask = repository.GetTaskById(taskId, CurrentUserId, CurrentBusinessId); EntityTask model = objTask.Model; var CreatedByName = CurrentUser.FirstName + " " + CurrentUser.LastName; var ReturnUrl = ConfigurationManager.AppSettings["BaseUrl"] + CurrentUser.BusinessName.Replace(" ", "-") + "#/tasks/" + model.ReferenceNumber; var rootPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath; var Subject = "Task " + model.ReferenceNumber + " - " + model.Subject + ""; var mail = new GMEmail(); string toEmails = null, practiceName = null, priorityType = null, targetDate = null, status = null; if (model.PracticeId.HasValue) { practiceName = new RepositoryLookups().GetPracticeNameById(model.PracticeId.Value); } if (model.PriorityTypeId.HasValue) { priorityType = EnumHelper.GetEnumName <TaskPriorities>(model.PriorityTypeId.Value); } targetDate = model.TargetDate.HasValue ? model.TargetDate.ToString() : "Not Set"; var AssignedUsers = string.Join(",", model.AssignedUsersList.Select(a => a.Name)); if (!string.IsNullOrEmpty(returnUrl)) { returnUrl += model.ReferenceNumber; } if (model.StatusId.HasValue) { status = Regex.Replace(EnumHelper.GetEnumName <TaskStatuses>(model.StatusId.Value), "([A-Z]{1,2}|[0-9]+)", " $1").Trim(); } if (CurrentUserId != model.RequestedUser.UserId) { var emailBody = TemplateManager.UpdateOrDeleteTask(rootPath, model.RequestedUser.Name, null, CreatedByName, model.Subject, targetDate, model.TaskDescription, practiceName, priorityType, status, ReturnUrl, false, CurrentBusinessId.Value, CurrentUser.RelativeUrl); mail.SendDynamicHTMLEmail(model.RequestedUser.Email, Subject, emailBody, CurrentUser.OtherEmails); } foreach (var item in model.AssignedUsersList) { if (item.UserId == CurrentUserId) { continue; } toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKSTATNFN"); if (!string.IsNullOrEmpty(toEmails)) { var emailBody = TemplateManager.UpdateOrDeleteTask(rootPath, item.Name, null, CreatedByName, model.Subject, targetDate, model.TaskDescription, practiceName, priorityType, status, ReturnUrl, false, CurrentBusinessId.Value, CurrentUser.RelativeUrl); mail.SendDynamicHTMLEmail(toEmails, Subject, emailBody, CurrentUser.OtherEmails); } } foreach (var item in model.WatchersList) { toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKSTATNFN"); if (!string.IsNullOrEmpty(toEmails)) { var emailBody = TemplateManager.UpdateOrDeleteTask(rootPath, item.Name, AssignedUsers, CreatedByName, model.Subject, targetDate, model.TaskDescription, practiceName, priorityType, status, ReturnUrl, true, CurrentBusinessId.Value, CurrentUser.RelativeUrl); mail.SendDynamicHTMLEmail(toEmails, Subject, emailBody, CurrentUser.OtherEmails); } } }
public override void OnAuthorization(HttpActionContext actionContext) { var httpContext = HttpContext.Current; var userName = ""; if (actionContext.Request.Headers.Any(a => a.Key == "User") && actionContext.Request.Headers.GetValues("User") != null) { var userNameHeader = actionContext.Request.Headers.GetValues("User"); userName = userNameHeader.FirstOrDefault(); IPrincipal genericPrincipal = new GenericPrincipal(new GenericIdentity(userName), null); actionContext.RequestContext.Principal = genericPrincipal; } if (httpContext.User.Identity.Name == "") { return; } var db = new CareConnectCrmEntities(); // var currentUserId = httpContext.User.Identity.GetUserId<int>(); var query = db.Users.Where(a => a.UserName == httpContext.User.Identity.Name); if (userName == "" && httpContext.User.Identity.IsAuthenticated) { query = db.Users.Where(a => a.UserName == httpContext.User.Identity.Name); } var userModel = db.Users.Where(a => a.UserName == httpContext.User.Identity.Name).Select(currentUser => new UserDetailsModel { Id = currentUser.Id, FirstName = currentUser.FirstName, MiddleName = currentUser.MiddleName, LastName = currentUser.LastName, BusinessId = currentUser.BusinessId, Email = currentUser.Email, PhoneNumber = currentUser.PhoneNumber, UserName = currentUser.UserName, BusinessName = currentUser.BusinessMaster.BusinessName, DomainUrl = currentUser.BusinessMaster.DomainUrl, RelativeUrl = currentUser.BusinessMaster.RelativeUrl, OtherEmails = currentUser.BusinessMaster.OtherEmails, IsRep = currentUser.Reps2.Any(), IsSalesManager = currentUser.RepgroupManagerMappers.Any(), IRoles = currentUser.Roles, IDepartments = currentUser.UserDepartments }).FirstOrDefault(); if (userModel == null) { return; } var profileRepository = new RepositoryUserProfile(); if (userModel.BusinessId == null || userModel.BusinessId == 0) { httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName; return; } userModel.UserPrivileges = profileRepository.GetUserPrivilages(userModel.Id); httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName; }
protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext) { return(true); #region Unreachable Code Block var userName = ""; if (actionContext.Request.Headers.GetValues("User") != null) { var userNameHeader = actionContext.Request.Headers.GetValues("User"); userName = userNameHeader.FirstOrDefault(); } else { var isAuthorized = base.IsAuthorized(actionContext); if (!isAuthorized) { //if (actionContext.Request.Headers.GetValues("User") != null) //{ // var userNameHeader = actionContext.Request.Headers.GetValues("User"); // userName = userNameHeader.FirstOrDefault(); //TODO: //add additional security validation cases // goto userLoggedIn; //} return(false); } } userLoggedIn: var httpContext = HttpContext.Current; if (httpContext.Items["CurrentUser"] != null) { } var db = new CareConnectCrmEntities(); // var currentUserId = httpContext.User.Identity.GetUserId<int>(); var query = db.Users.Where(a => a.UserName == userName); if (userName == "") { query = db.Users.Where(a => a.UserName == httpContext.User.Identity.Name); } var userModel = query .Select(currentUser => new UserDetailsModel { Id = currentUser.Id, FirstName = currentUser.FirstName, MiddleName = currentUser.MiddleName, LastName = currentUser.LastName, BusinessId = currentUser.BusinessId, Email = currentUser.Email, PhoneNumber = currentUser.PhoneNumber, UserName = currentUser.UserName, BusinessName = currentUser.BusinessMaster.BusinessName, RelativeUrl = currentUser.BusinessMaster.RelativeUrl, OtherEmails = currentUser.BusinessMaster.OtherEmails, IRoles = currentUser.Roles, IDepartments = currentUser.UserDepartments }).FirstOrDefault(); var profileRepository = new RepositoryUserProfile(); //userModel.Roles = profileRepository.GetAllUserRoles(userModel.Id).Model.ToNameArray(); //new string[] { "MasterAdmin", "SuperAdmin" }; //userModel.Departments = profileRepository.GetAllUserDepartments(userModel.Id).Model.ToNameArray(); if (userModel.BusinessId == null || userModel.BusinessId == 0) { httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName; return(false); } userModel.UserPrivileges = profileRepository.GetUserPrivilages(userModel.Id); httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName; return(true); #endregion }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var isAuthorized = base.AuthorizeCore(httpContext); if (!isAuthorized) { return(false); } UserDetailsModel userModel = null; if (HttpRuntime.Cache[httpContext.User.Identity.Name] != null) { userModel = (UserDetailsModel)HttpRuntime.Cache[httpContext.User.Identity.Name]; } else { var db = new CareConnectCrmEntities(); // var currentUserId = httpContext.User.Identity.GetUserId<int>(); userModel = db.Users.Where(a => a.UserName == httpContext.User.Identity.Name).Select(currentUser => new UserDetailsModel { Id = currentUser.Id, FirstName = currentUser.FirstName, MiddleName = currentUser.MiddleName, LastName = currentUser.LastName, BusinessId = currentUser.BusinessId, Email = currentUser.Email, PhoneNumber = currentUser.PhoneNumber, UserName = currentUser.UserName, BusinessName = currentUser.BusinessMaster.BusinessName, RelativeUrl = currentUser.BusinessMaster.RelativeUrl, IRoles = currentUser.Roles, IDepartments = currentUser.UserDepartments, OtherEmails = currentUser.BusinessMaster.OtherEmails, LogoUrl = currentUser.BusinessMaster.Logo }).FirstOrDefault(); var profileRepository = new RepositoryUserProfile(); if (userModel.BusinessId == null || userModel.BusinessId == 0) { httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentUserName"] = userModel.FirstName + " " + userModel.LastName; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName.Replace(" ", "-"); return(false); } userModel.UserPrivileges = profileRepository.GetUserPrivilages(userModel.Id); HttpRuntime.Cache[httpContext.User.Identity.Name] = userModel; } if (!userModel.Roles.Contains("BusinessAdmin")) { if (!userModel.UserPrivileges.Contains("RDSETTINGS")) { return(false); } } httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentUserName"] = userModel.FirstName + " " + userModel.LastName; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName.Replace(" ", "-"); return(true); }
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) { var httpContext = HttpContext.Current; if (!httpContext.User.Identity.IsAuthenticated) { throw new HttpException(403, "Access Denied"); } var userName = httpContext.User.Identity.Name; //if (actionContext.Request.Headers.GetValues("User") != null) //{ // var userNameHeader = actionContext.Request.Headers.GetValues("User"); // userName = userNameHeader.FirstOrDefault(); // var genericPrincipal = new System.Security.Principal.GenericPrincipal(new System.Security.Principal.GenericIdentity(userName), null); // actionContext.RequestContext.Principal = genericPrincipal; //} UserDetailsModel userModel = null; if (HttpRuntime.Cache[httpContext.User.Identity.Name] != null) { userModel = (UserDetailsModel)HttpRuntime.Cache[httpContext.User.Identity.Name]; } else { var db = new CareConnectCrmEntities(); // var currentUserId = httpContext.User.Identity.GetUserId<int>(); var query = db.Users.Where(a => a.UserName == userName); if (userName == "" && httpContext.User.Identity.IsAuthenticated) { query = db.Users.Where(a => a.UserName == httpContext.User.Identity.Name); } userModel = query .Select(currentUser => new UserDetailsModel { Id = currentUser.Id, FirstName = currentUser.FirstName, MiddleName = currentUser.MiddleName, LastName = currentUser.LastName, BusinessId = currentUser.BusinessId, Email = currentUser.Email, PhoneNumber = currentUser.PhoneNumber, UserName = currentUser.UserName, BusinessName = currentUser.BusinessMaster.BusinessName, DomainUrl = currentUser.BusinessMaster.DomainUrl, RelativeUrl = currentUser.BusinessMaster.RelativeUrl, OtherEmails = currentUser.BusinessMaster.OtherEmails, IsRep = currentUser.Reps2.Any(), IsSalesManager = currentUser.RepgroupManagerMappers.Any(), DefaultDateRange = currentUser.BusinessMaster.DateRange, IRoles = currentUser.Roles, IDepartments = currentUser.UserDepartments, SalesGroupBy = currentUser.BusinessMaster.SalesGroupBy, LogoUrl = currentUser.BusinessMaster.Logo }).FirstOrDefault(); var profileRepository = new RepositoryUserProfile(); userModel.UserPrivileges = profileRepository.GetUserPrivilages(userModel.Id); HttpRuntime.Cache[httpContext.User.Identity.Name] = userModel; } if (userModel.BusinessId == null || userModel.BusinessId == 0) { httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName; return; } httpContext.Items["CurrentUser"] = userModel; httpContext.Items["CurrentBusinessName"] = userModel.BusinessName; }
public IHttpActionResult InsertNotedata(VMNoteModel entity) { var repository = new RepositoryNote(); var response = new DataResponse(); if (ModelState.IsValid) { string typeValue = ControllerContext.RouteData.Values["Type"].ToString(); entity.ParentId = int.Parse(ControllerContext.RouteData.Values["ParentId"].ToString()); switch (typeValue) { case "tasks": entity.ParentTypeId = (int)NoteType.Task; break; case "leads": entity.ParentTypeId = (int)NoteType.Lead; break; } var model = new EntityNote { Id = entity.Id, ParentId = entity.ParentId, ParentTypeId = entity.ParentTypeId, CreatedBy = CurrentUser.Id, UpdatedBy = CurrentUser.Id, Description = entity.Description, }; response = repository.SaveNote(model); if (entity.ParentTypeId == (int)NoteType.Task && response.Message == "OK") { #region Send email to users in assigned to and watchers list var CreatedByName = string.Format("{0} {1}", CurrentUser.FirstName, CurrentUser.LastName); var TaskModel = new RepositoryTask().GetTaskById(model.ParentId, CurrentUserId, CurrentBusinessId); try { var rootPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath; var ReturnUrl = ConfigurationManager.AppSettings["BaseUrl"] + CurrentUser.BusinessName.Replace(" ", "-") + "#/tasks/" + TaskModel.Model.ReferenceNumber; var Subject = "Task " + TaskModel.Model.ReferenceNumber + " - " + TaskModel.Model.Subject + ""; var mail = new GMEmail(); string toEmails = null; if (CurrentUserId != TaskModel.Model.RequestedUser.UserId) { try { var emailBody = TemplateManager.NewNote(rootPath, TaskModel.Model.RequestedUser.Name, CreatedByName, TaskModel.Model.Subject, ReturnUrl, entity.Description, CurrentBusinessId.Value, CurrentUser.RelativeUrl); mail.SendDynamicHTMLEmail(TaskModel.Model.RequestedUser.Email, Subject, emailBody, CurrentUser.OtherEmails); } catch (Exception ex) { ex.Log(); } } var UserList = TaskModel.Model.AssignedUsersList.Concat(TaskModel.Model.WatchersList); foreach (var item in UserList) { if (item.UserId == CurrentUserId) { continue; } var emailBody = TemplateManager.NewNote(rootPath, item.Name, CreatedByName, TaskModel.Model.Subject, ReturnUrl, entity.Description, CurrentBusinessId.Value, CurrentUser.RelativeUrl); try { toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKNOTENFN"); if (!string.IsNullOrEmpty(toEmails)) { mail.SendDynamicHTMLEmail(item.Email, Subject, emailBody, CurrentUser.OtherEmails); } } catch (Exception ex) { ex.Log(); } } } catch (Exception ex) { ex.Log(); } #endregion } } else { var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new { Key = s.Key.Split('.').Last(), Message = s.Value.Errors[0].ErrorMessage }); return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList })); } return(Ok <DataResponse>(response)); }