示例#1
0
        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();
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        public Task SendAsync(IdentityMessage message)
        {
            var mail = new GMEmail();

            //if (ApplicationConfig.GetAppSettings("IsInDemo") == "true")
            //{
            //    mail.To.Add(ApplicationConfig.GetAppSettings("DemoEmailId"));
            //}
            //else
            //{
            mail.To.Add(message.Destination);
            mail.Subject = message.Subject;
            mail.Body    = message.Body;

            #region manage bcc for developers

            string _bcc = ConfigurationManager.AppSettings["DevNotification"];
            if (!string.IsNullOrEmpty(_bcc))
            {
                var arrayBcc = _bcc.Split(',');
                foreach (var email in arrayBcc)
                {
                    if (!string.IsNullOrEmpty(email))
                    {
                        mail.Bcc.Add(email);
                    }
                }
            }

            #endregion
            try
            {
                mail.SendMessage();
            }
            catch (Exception ex) { }
            // Plug in your email service here to send an email.
            return(Task.FromResult(0));
        }
示例#4
0
        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 }));
            }
        }
示例#5
0
        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 IHttpActionResult SetPrivileges(int?UserId, List <Modulesmodels> model)
        {
            var response             = new DataResponse <VMPrivilege>();
            List <Privileges> entity = new List <Privileges>();

            foreach (var module in model)
            {
                foreach (var privilege in module.UserPrivileges)
                {
                    if (privilege.Id != 0)
                    {
                        entity.Add(new Privileges
                        {
                            UserId     = UserId.Value,
                            Id         = privilege.Id,
                            Name       = privilege.Name,
                            Deny       = privilege.Deny,
                            businessId = CurrentBusinessId
                        });
                    }
                }
            }

            response = repository.SetPrivileges(entity, UserId.Value, CurrentBusinessId.Value);
            if (response.Status == DataResponseStatus.OK)
            {
                //Privilege mail
                if (response.Model != null)
                {
                    var RootPath  = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
                    var ReturnUrl = ConfigurationManager.AppSettings["BaseUrl"] + CurrentUser.RelativeUrl.Replace(" ", "-");

                    string Subject = string.Empty;
                    if (response.Model.UserPrivilegesList != null && response.Model.UserPrivileges.Count() > 0)
                    {
                        Subject = "Privileges";
                    }
                    else
                    {
                        Subject = "Privilege";
                    }

                    //Building an HTML string.
                    StringBuilder html  = new StringBuilder();
                    int           index = 1;
                    foreach (var item in response.Model.UserPrivilegesList)
                    {
                        //UserDepartments = string.Join("<br/>", response.Model.UserDepartmentName);
                        html.Append("<tr><td style = border:1px solid #f0f0f0;border-width:1px 0;padding:11px 0;vertical-align:baseline>" +
                                    "<div style = margin: 0 12px 0 0;border :2px solid #e6e6e6;border-radius :10px 31px;padding :7px 12px;background :#f5f5f5;>");
                        html.Append(index);
                        html.Append("</div>" +
                                    "</td>" +
                                    "<td style = border:1px solid #f0f0f0;border-width:1px 0;padding:11px 0;width:100%>" +
                                    "<div style =font-family:Roboto-Regular,Helvetica,Arial,sans-serif;font-size:13px;color:#202020;line-height:1.5;font-weight:bold>");
                        html.Append(item.Title);
                        html.Append("</div>" +
                                    "<div style = font-family:Roboto-Regular,Helvetica,Arial,sans-serif;font-size:13px;color:#202020;line-height:1.5>");
                        html.Append(item.Description);
                        html.Append("</div>" +
                                    "</td>" +
                                    " </tr>");
                        index++;
                    }

                    string AssignedUserName = response.Model.UserName;
                    var    mail             = new GMEmail();

                    string emailBody = TemplateManager.AddPrivilegesToUser(RootPath, Subject, AssignedUserName, html.ToString(), CurrentUser.FirstName, ReturnUrl);
                    mail.SendDynamicHTMLEmail(response.Model.Email, "New Privilege Added", emailBody, "", "");
                }
            }
            return(Ok <DataResponse>(response));
        }
        public async Task <IHttpActionResult> InsertUserData(UserViewModel model)
        {
            var response = new DataResponse <EntityUsers>();

            try
            {
                if (model.RoleIds.Count == 0)
                {
                    return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = "Plese select at least one role." }));
                }

                model.Password = model.ConfirmPassword = GeneralHelpers.GeneratePassword(3, 2, 2);

                var user = new GMUser {
                    FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, UserName = model.Email, Email = model.Email, BusinessId = CurrentBusinessId, IsActive = true
                };
                var adminresult = await UserManager.CreateAsync(user, model.Password);

                if (adminresult.Succeeded)
                {
                    var entity = new EntityProfile
                    {
                        UserId          = user.Id,
                        WorkEmail       = model.WorkEmail,
                        HomePhone       = model.HomePhone,
                        AdditionalPhone = model.AdditionalPhone,
                        AddressLine1    = model.AddressLine1,
                        AddressLine2    = model.AddressLine2,
                        City            = model.City,
                        Zip             = model.Zip,
                        StateId         = model.StateId,
                        CreatedBy       = CurrentUserId,
                        UpdatedBy       = CurrentUserId,
                        Startdate       = string.IsNullOrEmpty(model.StartDate) ? (DateTime?)null : DateTime.ParseExact(model.StartDate, "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None),
                        DepartmentIds   = model.DepartmentIds
                    };

                    if (model.RoleIds != null)
                    {
                        IdentityResult result = null;
                        foreach (var roleId in model.RoleIds)
                        {
                            result = await UserManager.AddToRoleAsync(user.Id, roleId.ToString());
                        }
                    }
                    response = repository.insertUserProfile(entity);

                    if (model.RepGroupId > 0)
                    {
                        new RepositoryReps().Insert(new EBP.Business.Entity.Rep.EntityReps {
                            UserId = user.Id, RepGroupId = model.RepGroupId, CreatedBy = CurrentUserId
                        });
                    }

                    try
                    {
                        var RootPath  = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
                        var ReturnUrl = ConfigurationManager.AppSettings["BaseUrl"] + CurrentUser.RelativeUrl.Replace(" ", "-");

                        string UserDepartments = string.Empty;
                        if (response.Model.UserDepartmentName != null && response.Model.UserDepartmentName.Count() > 0)
                        {
                            UserDepartments = string.Join("<br/>", response.Model.UserDepartmentName);
                        }
                        //Email to user
                        var    mail      = new GMEmail();
                        string emailBody = TemplateManager.NewUserCreate(RootPath, CurrentUser.BusinessName, user.UserName, model.Password, user.FirstName, UserDepartments, ReturnUrl);
                        mail.SendDynamicHTMLEmail(model.Email, "New user registration", emailBody, "", "");
                    }
                    catch (Exception ex)
                    {
                        ex.Log();
                    }
                }
                else
                {
                    return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = adminresult.Errors.First() }));
                }
                return(Ok <DataResponse>(response));
            }
            catch (Exception ex)
            {
                ex.Log();
            }

            return(Ok <DataResponse>(response));
        }
示例#8
0
        public async Task <IHttpActionResult> CreateBusiness(BusinessMasterModel model)
        {
            var response = new DataResponse <EntityBusinessMaster>();

            var userManager = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <GMUserManager>();
            var roleManager = System.Web.HttpContext.Current.GetOwinContext().Get <GMRoleManager>();

            if (ModelState.IsValid)
            {
                if (db.BusinessMasters.Any(a => a.BusinessName.ToLower() == model.BusinessName.ToLower()))
                {
                    var error = string.Format("{0} is already used.", model.BusinessName);
                    return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = error }));
                }

                model.Password = GeneralHelpers.GeneratePassword(3, 2, 2);
                var user = new GMUser
                {
                    FirstName   = model.FirstName,
                    MiddleName  = model.MiddleName,
                    LastName    = model.LastName,
                    PhoneNumber = model.PhoneNumber,
                    UserName    = model.Email,
                    Email       = model.Email,
                    IsActive    = true,
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var roleName = "BusinessAdmin";
                    var role     = roleManager.FindByName(roleName);
                    if (role == null)
                    {
                        db.Roles.Add(new Role {
                            Name = roleName, Description = roleName, IsActive = true, CreatedBy = 1, CreatedOn = System.DateTime.UtcNow
                        });
                        db.SaveChanges();
                    }
                    UserManager.AddToRolesAsync(user.Id, roleName);
                }
                else
                {
                    var error = string.Format("{0} is already used.", model.Email);
                    return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = error }));
                }

                var entityBusinessProfile = new EntityBusinessMaster();
                entityBusinessProfile.BusinessName = model.BusinessName;
                entityBusinessProfile.RelativeUrl  = model.BusinessName.ToLower().Replace(" ", "-");
                entityBusinessProfile.Description  = model.Description;
                entityBusinessProfile.CreatedBy    = 1;
                response = repository.Insert(entityBusinessProfile);

                if (response.Model.Id > 0)
                {
                    var userDetails = db.Users.FirstOrDefault(a => a.Id == user.Id);
                    userDetails.UserProfiles.Add(new UserProfile {
                        CreatedBy = 1, CreatedOn = DateTime.UtcNow, UserId = userDetails.Id
                    });
                    userDetails.BusinessId = response.Model.Id;
                    db.SaveChanges();

                    model.RootPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
                    string ReturnUrl = ConfigurationManager.AppSettings["BaseUrl"];
                    ReturnUrl = ReturnUrl + model.BusinessName.Replace(" ", "-");
                    string RelativeUrl = model.BusinessName.ToLower().Replace(" ", "-");

                    string managerEmailBody = string.Empty;
                    var    mail             = new GMEmail();
                    managerEmailBody = TemplateManager.NewBusinessCreate(model.RootPath, model.BusinessName, user.UserName, model.Password, model.FirstName, ReturnUrl, response.Model.Id, RelativeUrl);
                    mail.SendDynamicHTMLEmail(model.Email, "New Business Created", managerEmailBody, CurrentUser.OtherEmails);

                    //string rootPath = ConfigurationManager.AppSettings["FolderPath"];
                    string        rootPath = HttpContext.Current.Server.MapPath("~/Assets");
                    string        path     = Path.Combine(rootPath, response.Model.Id.ToString());
                    DirectoryInfo dir      = new DirectoryInfo(path);
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                }
            }

            return(Ok <DataResponse>(response));
        }
        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));
        }