Esempio n. 1
0
        public IHttpActionResult DeleteFile(int id)
        {
            var repository = new RepositoryTask();
            var response   = repository.DeleteFile(id);

            return(Ok <DataResponse>(response));
        }
        public IHttpActionResult TogglePriority(int id)
        {
            var repository = new RepositoryTask();
            var response   = repository.TogglePriority(id, CurrentUserId);

            return(Ok <DataResponse>(response));
        }
Esempio n. 3
0
 public CompanyUnitOfWork(CompanyContext context)
 {
     this.context = context;
     Employee     = new RepositoryEmployee(context);
     Department   = new RepositoryDepartment(context);
     Task         = new RepositoryTask(context);
 }
Esempio n. 4
0
        public IHttpActionResult SaveAlertDate(TaskDates tarskDates)
        {
            var repository = new RepositoryTask();
            var response   = repository.SaveAlertDate(tarskDates.AlertDate, tarskDates.TaskId, CurrentUserId);

            return(Ok <DataResponse>(response));
        }
        public IHttpActionResult GetTaskById(int?TaskId)
        {
            var response   = new DataResponse <EntityTask>();
            var repository = new RepositoryTask();

            if (TaskId.HasValue)
            {
                response = repository.GetTaskById(TaskId.Value, CurrentUserId, CurrentBusinessId);

                if (response.Model != null)
                {
                    //response.Model.CreatedOn = response.Model.CreatedOn.ToLocalTime();

                    if (response.Model.TargetDate.HasValue)
                    {
                        response.Model.TargetDate = response.Model.TargetDate.Value.ToLocalTime();
                    }

                    if (response.Model.AlertDate.HasValue)
                    {
                        response.Model.AlertDate = response.Model.AlertDate.Value.ToLocalTime();
                    }
                }
            }
            else
            {
                response.Model = new EntityTask();
            }
            return(Ok <DataResponse>(response));
        }
Esempio n. 6
0
        public IHttpActionResult ToggleStatus(int id)
        {
            string[] taskDeletePrivileges = { "DLTALLINTSK" };
            var      repository           = new RepositoryTask();
            var      response             = repository.ToggleStatus(id, CurrentUserId, HasRight(taskDeletePrivileges));

            return(Ok <DataResponse>(response));
        }
Esempio n. 7
0
 public void Add(RepositoryTask task)
 {
     if (stopped == false)
     {
         items.Enqueue(task);
         onReady?.Set();
     }
 }
Esempio n. 8
0
        public IHttpActionResult TogglePriority(int id)
        {
            var repository = new RepositoryTask();
            var response   = repository.TogglePriority(id, CurrentUserId);

            response.Message = "success";
            response.Status  = DataResponseStatus.OK;
            return(Ok <DataResponse>(response));
        }
        public IHttpActionResult SetLeadStatus(int taskid, int statusid)
        {
            var repository    = new RepositoryTask();
            var UpdatedByName = CurrentUser.FirstName + " " + CurrentUser.LastName;
            var response      = repository.SetStatus(taskid, statusid, CurrentUserId, UpdatedByName);

            SendEmailNotification(ConfigurationManager.AppSettings["BaseUrl"] + CurrentUser.BusinessName.Replace(" ", "-") + "#/tasks/", taskid);

            return(Ok <DataResponse>(response));
        }
        public IHttpActionResult ToggleActiveStatus(int taskid)
        {
            var repository = new RepositoryTask();

            string[] taskDeletePrivileges = { "DLTALLINTSK" };
            var      response             = repository.ToggleStatus(taskid, CurrentUserId, HasRight(taskDeletePrivileges));

            SendEmailNotification(null, taskid);

            return(Ok <DataResponse>(response));
        }
Esempio n. 11
0
        public IHttpActionResult GetTaskById(int?TaskId)
        {
            var response   = new DataResponse <EntityTask>();
            var repository = new RepositoryTask();

            if (TaskId.HasValue)
            {
                response = repository.GetTaskById(TaskId.Value, CurrentUserId, CurrentBusinessId, true);
            }
            else
            {
                response.Model = new EntityTask();
            }
            return(Ok <DataResponse>(response));
        }
Esempio n. 12
0
        public IHttpActionResult GetByFilter(FilterTask filter)
        {
            string[] allowedRoles         = { "RDTSK" };
            string[] superRoles           = { "RDTSKALL" };
            string[] taskDeletePrivileges = { "DLTALLINTSK" };

            if (HasRight(allowedRoles) || HasRight(superRoles))
            {
                var repository = new RepositoryTask();

                var response = repository.GetTasks(filter, CurrentUserId, CurrentBusinessId, HasSuperRight(superRoles), HasRight(taskDeletePrivileges), true);
                return(Ok <DataResponse <EntityList <EntityTask> > >(response));
            }
            else
            {
                return(Ok <DataResponse>(null));
            }
        }
Esempio n. 13
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 }));
            }
        }
Esempio n. 14
0
        public IHttpActionResult GetTaskLogs(int id)
        {
            var response = new RepositoryTask().GetTaskLogs(id, CurrentUserId);

            return(Ok <DataResponse <EntityTaskLog> >(response));
        }
Esempio n. 15
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 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));
        }
Esempio n. 17
0
 private void OnCompleted(RepositoryTask task)
 {
     task.Release(this);
     onReady.Set();
 }