public static List <TaskGroupModel> ToTaskGroup(DbDataReader readers)
        {
            if (readers == null)
            {
                return(null);
            }
            var models = new List <TaskGroupModel>();

            while (readers.Read())
            {
                var model = new TaskGroupModel
                {
                    Id              = Convert.ToInt32(readers["Id"]),
                    Name            = Convert.IsDBNull(readers["Name"]) ? string.Empty : Convert.ToString(readers["Name"]),
                    Description     = Convert.IsDBNull(readers["Description"]) ? string.Empty : Convert.ToString(readers["Description"]),
                    BackGroundColor = Convert.IsDBNull(readers["BackGroundColor"]) ? string.Empty : Convert.ToString(readers["BackGroundColor"]),
                    CreatedAt       = Convert.IsDBNull(readers["CreatedAt"]) ? (DateTime?)null : Convert.ToDateTime(readers["CreatedAt"]),
                    CreatedById     = Convert.IsDBNull(readers["CreatedById"]) ? string.Empty : Convert.ToString(readers["CreatedById"]),
                };

                models.Add(model);
            }

            return(models);
        }
Ejemplo n.º 2
0
        public virtual IActionResult Create(TaskGroupModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaskGroup))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var item = model.ToEntity <TaskGroup>();

                //ensure we have "/" at the end


                _taskGroupService.InsertTaskGroup(item);

                //activity log
                _customerActivityService.InsertActivity("AddNewTaskGroup",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewTaskGroup"), item.Id), item);

                SuccessNotification(_localizationService.GetResource("AppWork.Contracts.TaskGroup.Added"));

                return(continueEditing ? RedirectToAction("Edit", new { id = item.Id }) : RedirectToAction("List"));
            }

            //prepare model
            model = _taskModelFactory.PrepareTaskGroupModel(model, null);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int groupId)
        {
            var group = await _taskGroupService.GetAsync(groupId);

            var users = await _userService.BrowseAsync();

            var taskGroup = new TaskGroupModel()
            {
                Id        = group.TaskGroupId,
                Name      = group.Name,
                UserTasks = group.UserTasks.Select(t => new UserTaskModel
                {
                    UserTaskId  = t.UserTaskId,
                    TaskGroupId = t.TaskGroupId,
                    Name        = t.Name,
                    Deadline    = t.Deadline,
                    Status      = t.Status.ToString(),
                    UserId      = t.UserId
                }).ToList()
            };

            var model = new EditModel()
            {
                TaskGroup = taskGroup,
                UserTask  = new UserTaskModel(),
                Users     = users.Select(u => new UserModel
                {
                    UserId    = u.UserId,
                    Firstname = u.FirstName,
                    Lastname  = u.LastName
                }).ToList()
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CreateGroup(TaskGroupModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var name = model.Name;

            var id = await _taskGroupService.CreateAsync(name);

            return(RedirectToAction("Edit", "TaskGroup", new { groupId = id }));
        }
        public ResponseModel SaveTaskGroup(TaskGroupModel model)
        {
            var errMessage     = string.Empty;
            var queryParamList = new QueryParamList
            {
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@Id", ParamValue = model.Id
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@Name", ParamValue = model.Name
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@Description", ParamValue = model.Description
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@BackGroundColor", ParamValue = model.BackGroundColor
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@CreatedAt", ParamValue = DateTime.UtcNow, DBType = DbType.DateTime
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@CreatedById", ParamValue = model.CreatedById
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@CompanyId", ParamValue = model.CompanyId
                }
            };

            const string sql = @"IF NOT EXISTS(SELECT TOP 1 P.Id FROM ResourceTracker_TaskGroup P WHERE P.Id=@Id)
                                BEGIN
         
                                 INSERT INTO ResourceTracker_TaskGroup(Name,Description,BackGroundColor,CreatedAt,CreatedById,CompanyId)
				                 VALUES(@Name,@Description,@BackGroundColor,@CreatedAt,@CreatedById,@CompanyId)
                                END
                                ELSE
                                BEGIN
                                  UPDATE ResourceTracker_TaskGroup SET Name=@Name,Description=@Description,BackGroundColor=@BackGroundColor
	                              WHERE Id=@Id
                                END";

            DBExecCommandEx(sql, queryParamList, ref errMessage);

            return(new ResponseModel {
                Success = string.IsNullOrEmpty(errMessage)
            });
        }
Ejemplo n.º 6
0
        public int AddTaskGroup(TaskGroupModel taskGroup)
        {
            if (taskGroup == null)
            {
                throw new BaseException("TaskGroupService: Insert TaskGroupService did not receive a valid TaskGroup");
            }

            if (string.IsNullOrEmpty(taskGroup.GroupName))
            {
                throw new BaseException("Invalid Task Group Name");
            }

            if (TaskGroupRepo.GetByName(taskGroup.GroupName) != null)
            {
                throw new BaseException("This task already exists");
            }

            return(TaskGroupRepo.AddTaskGroup(taskGroup));
        }
Ejemplo n.º 7
0
        public int AddTaskGroup(TaskGroupModel taskGroup)
        {
            var dbTg  = DbContext.TaskGroups.Where(x => x.Id_TaskGroup == taskGroup.Id_TaskGroupModel).FirstOrDefault();
            var toAdd = false;

            if (dbTg == null)
            {
                dbTg  = new TaskGroups();
                toAdd = true;
            }

            dbTg.GroupName = taskGroup.GroupName;

            if (toAdd)
            {
                DbContext.TaskGroups.Add(dbTg);
            }

            return(DbContext.SaveChanges());
        }
Ejemplo n.º 8
0
        public virtual IActionResult Edit(TaskGroupModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaskGroup))
            {
                return(AccessDeniedView());
            }

            //try to get a store with the specified id
            var item = _taskGroupService.GetTaskGroupById(model.Id);

            if (item == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                item = model.ToEntity(item);


                _taskGroupService.UpdateTaskGroup(item);

                //activity log
                _customerActivityService.InsertActivity("EditTaskGroup",
                                                        string.Format(_localizationService.GetResource("ActivityLog.EditTaskGroup"), item.Id), item);



                SuccessNotification(_localizationService.GetResource("AppWork.Contracts.TaskGroup.Updated"));

                return(continueEditing ? RedirectToAction("Edit", new { id = item.Id }) : RedirectToAction("List"));
            }

            //prepare model
            model = _taskModelFactory.PrepareTaskGroupModel(model, item, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="executionDate"></param>
        /// <returns></returns>
        public ActionResult GetAdminStatus(string fromDate, string toDate)
        {
            int employeeId = this.db.Logins.Where(x => x.UserId.Equals(this.CurrentUserId)).FirstOrDefault().Employee.Id;

            DateTime Fromdate = Convert.ToDateTime(fromDate);
            DateTime Todate   = Convert.ToDateTime(toDate);

            IQueryable <Task> tasks = this.db.Tasks.Where(x => x.CreatedOn >= Fromdate && x.CreatedOn <= Todate);

            var tasksgrp = from t in db.Tasks
                           join p in db.Projects on t.ProjectId equals p.Id
                           join w in db.WorkCodesActivities on t.WorkCodeActivityId equals w.Id
                           join e in db.Employees on t.EmployeeId equals e.Id
                           where t.ExecutionDate >= Fromdate && t.ExecutionDate <= Todate

                           select new { projectname = p.Name, workcode = w.Name, empname = e.LastName + " " + e.FirstName };


            List <TaskGroupModel> results = new List <TaskGroupModel>();

            if (tasksgrp != null)
            {
                foreach (var result in tasksgrp)
                {
                    TaskGroupModel taskgrpmodel = new TaskGroupModel();
                    taskgrpmodel.projectname = result.projectname;
                    taskgrpmodel.workcode    = result.workcode;
                    taskgrpmodel.empname     = result.empname;

                    results.Add(taskgrpmodel);
                }
                return(Json(results, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(new JsonResult());
            }
        }
Ejemplo n.º 10
0
        public TaskGroupModel PrepareTaskGroupModel(TaskGroupModel model, TaskGroup item, bool excludeProperties = false)
        {
            if (item != null)
            {
                //fill in model values from the entity
                model = model ?? item.ToModel <TaskGroupModel>();
            }
            var    items   = _taskGroupService.GetAllTaskGroups();
            string treetam = "";

            model.AvaibleTaskGroupList = items.Select(c => new SelectListItem
            {
                Value    = c.Id.ToString(),
                Text     = treetam.PadLeft(c.TreeLevel, '-') + c.Name,
                Selected = c.Id == model.ParentId
            }).ToList();
            model.AvaibleTaskGroupList.Insert(0, new SelectListItem
            {
                Value = "0",
                Text  = "--Chọn tỷ lệ khoán cha--",
            });
            return(model);
        }
Ejemplo n.º 11
0
        public ActionResult Edit(TaskGroupModel model)
        {
            var taskGroup = _taskGroupRepository.GetById(model.Id);

            if (ModelState.IsValid)
            {
                taskGroup = model.ToEntity(taskGroup);

                //always set IsNew to false when saving
                taskGroup.IsNew = false;
                _taskGroupRepository.Update(taskGroup);

                //commit all changes
                this._dbContext.SaveChanges();

                //notification
                SuccessNotification(_localizationService.GetResource("Record.Saved"));
                return(new NullJsonResult());
            }
            else
            {
                return(Json(new { Errors = ModelState.SerializeErrors() }));
            }
        }
Ejemplo n.º 12
0
        public TaskGroup AddTaskGroup(TaskGroupModel taskGroup)
        {
            TaskGroup tempTaskGroup;

            try
            {
                var opProject   = DataContext.Projects.SingleOrDefault(p => p.Id == taskGroup.ProjectId);
                var opMember    = DataContext.Members.SingleOrDefault(m => m.Id == taskGroup.ManagerId);
                var opTaskGroup = new TaskGroup()
                {
                    Name             = taskGroup.Name,
                    Project          = opProject,
                    TaskGroupManager = opMember
                };
                tempTaskGroup = base.DataContext.TaskGroups.Add(opTaskGroup).Entity;
                base.DataContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(tempTaskGroup);
        }
Ejemplo n.º 13
0
 public TaskGroup AddTaskGroup([FromBody] TaskGroupModel taskGroup)
 {
     return(_taskGroupService.AddTaskGroup(taskGroup));
 }
Ejemplo n.º 14
0
 public IHttpActionResult AddTaskGroup([FromBody] TaskGroupModel taskGroup)
 {
     return(Ok(taskGroupService.AddTaskGroup(taskGroup)));
 }
Ejemplo n.º 15
0
        public IHttpActionResult SaveTaskGroup(TaskGroupModel model)
        {
            var result = _taskRepository.SaveTaskGroup(model);

            return(Ok(result));
        }