Пример #1
0
        public ActionResult Create(TasksModel model)
        {
            if (!CurrentUser.IsManager)
            {
                return(RedirectToAction("NotFound", "Home"));
            }

            if (!string.IsNullOrEmpty(model.Name))
            {
                var task = new Task();
                task.ProjectId   = model.ProjectId;
                task.Leader      = model.Leader;
                task.Name        = model.Name;
                task.Priority    = model.Priority;
                task.Description = model.Description;
                task.CreateBy    = CurrentUser.Id;
                task.ModifyBy    = CurrentUser.Id;
                task.CreateDate  = DateTime.Now;
                task.ModifyDate  = DateTime.Now;
                if (!string.IsNullOrEmpty(model.StartAndEndDate) && model.StartAndEndDate.Split('-').Length == 2)
                {
                    var      strStart = model.StartAndEndDate.Split('-')[0].Trim();
                    var      strEnd   = model.StartAndEndDate.Split('-')[1].Trim();
                    DateTime sdate;
                    DateTime edate;
                    if (DateTime.TryParseExact(strStart, Helper.FormatDate,
                                               new CultureInfo("en-US"),
                                               DateTimeStyles.None,
                                               out sdate))
                    {
                        task.StartDate = sdate;
                    }

                    if (DateTime.TryParseExact(strEnd, Helper.FormatDate,
                                               new CultureInfo("en-US"),
                                               DateTimeStyles.None,
                                               out edate))
                    {
                        task.EndDate = edate;
                    }

                    TaskBO.Insert(task);
                    var department = DepartmentBO.GetById(task.Leader);
                    if (department != null && department.UserId > 0)
                    {
                        AlertBO.Insert(task.Name, (int)AlertType.Task, 0, department.UserId);
                    }

                    //TODO ... Insert document
                }
                return(RedirectToAction("Index"));
            }

            PreparingData();
            return(View(model));
        }
Пример #2
0
 public ActionResult Delete(int departmentId)
 {
     if (DepartmentBO.GetById(departmentId) != null)
     {
         DepartmentBO.Delete(departmentId);
         return(RedirectToAction("Index"));
     }
     else
     {
         //ModelState.AddModelError("", "Có lỗi trong quá trình xóa");
         return(RedirectToAction("NotFound", "Home"));
     }
     return(View());
 }
Пример #3
0
        public ActionResult Index(UserSearchModel searchModel)
        {
            var listUser = new List <UserDisplayModel>();

            if (searchModel == null)
            {
                searchModel = new UserSearchModel();
            }

            var departments = new List <Department>();

            departments.Add(new Department {
                Id = 0, Name = "--- All ---"
            });
            departments.AddRange(DepartmentBO.GetAll());
            ViewBag.Departments = departments;
            var users = UserBO.Search(searchModel.UserName, searchModel.FullName, searchModel.DepartmentId);

            foreach (var item in users)
            {
                var department = DepartmentBO.GetById(item.DepartmentId);
                var model      = new UserDisplayModel
                {
                    Id             = item.Id,
                    UserName       = item.UserName,
                    FirstName      = item.FirstName,
                    LastName       = item.LastName,
                    Password       = item.Password,
                    Address        = item.Address,
                    Avatar         = item.Avatar,
                    DateOfBirth    = item.DateOfBirth.ToString("dd/MM/yyyy"),
                    DepartmentId   = item.DepartmentId,
                    DepartmentName = department == null? string.Empty : department.Name,
                    Gender         = item.Gender,
                    Email          = item.Email,
                    Mission        = item.Mission,
                    IsActive       = item.IsActive,
                    IsAdmin        = item.IsAdmin,
                    CreatedDate    = item.CreateDate == null ? string.Empty : ((DateTime)item.CreateDate).ToString(Helper.FormatDate),
                };
                listUser.Add(model);
            }

            searchModel.Users = listUser;
            return(View(searchModel));
        }
Пример #4
0
 public ActionResult Edit(DepartmentModel model)
 {
     if (DepartmentBO.GetById(model.Id) != null)
     {
         if (Validate(model))
         {
             DepartmentBO.Update(model.Id, model.Name, model.UserId, DateTime.Now, DateTime.Now, CurrentUser.Id, CurrentUser.Id);
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(RedirectToAction("NotFound", "Home"));
     }
     ViewBag.ListUsers = UserBO.GetAll();
     return(View(model));
 }
Пример #5
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                // Pass 123456: dSVrtpZkGVI=
                var user = UserBO.Login(model.UserName, EncryptUtils.Encrypt(model.Password));
                if (user != null)
                {
                    user.Department = DepartmentBO.GetById(user.DepartmentId);
                    FormsAuthentication.SetAuthCookie(JsonConvert.SerializeObject(user, Formatting.None), false);
                    return(RedirectToAction("Index", "Home"));
                }
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "User or password incorrect");
            return(View(model));
        }
Пример #6
0
        public ActionResult Edit(int id)
        {
            ViewBag.CurrentUser = CurrentUser;
            ViewBag.ListUsers   = UserBO.GetAll();
            var department = DepartmentBO.GetById(id);

            if (department == null)
            {
                return(RedirectToAction("NotFound", "Home"));
            }
            var model = new DepartmentModel()
            {
                Id     = department.Id,
                Name   = department.Name,
                UserId = department.UserId,
            };

            return(View("Create", model));
        }
Пример #7
0
        //
        // GET: /Task/

        public ActionResult Index(TasksSearchModel searchModel)
        {
            var listTasks = new List <TasksDisplayModel>();

            if (searchModel == null)
            {
                searchModel = new TasksSearchModel
                {
                    StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString(Helper.FormatDate),
                    EndDate   = new DateTime(DateTime.Now.Year, DateTime.Now.Month + 1, 1).AddDays(-1).ToString(Helper.FormatDate),
                };
            }
            DateTime sdate;
            DateTime edate;

            DateTime.TryParseExact(searchModel.StartDate, Helper.FormatDate,
                                   new CultureInfo("en-US"),
                                   DateTimeStyles.None,
                                   out sdate);
            DateTime.TryParseExact(searchModel.EndDate, Helper.FormatDate,
                                   new CultureInfo("en-US"),
                                   DateTimeStyles.None,
                                   out edate);

            var departments = new List <Department> {
                new Department {
                    UserId = 0, Name = "--- All ---"
                }
            };

            departments.AddRange(DepartmentBO.GetAll());
            ViewBag.Departments = departments;

            var projects = new List <Project> {
                new Project {
                    Id = 0, Name = "--- All ---"
                }
            };

            projects.AddRange(ProjectBO.GetAll());
            ViewBag.Projects = projects;

            var tasks = TaskBO.Search(searchModel.Name, searchModel.Leader, sdate, edate);

            foreach (var item in tasks)
            {
                var department = DepartmentBO.GetById(item.Leader);
                var project    = ProjectBO.GetById(item.ProjectId);
                var model      = new TasksDisplayModel
                {
                    Id          = item.Id,
                    ProjectId   = item.ProjectId,
                    ProjectName = project.Name,
                    Name        = item.Name,
                    Description = item.Description,
                    Leader      = item.Leader,
                    LeaderName  = department.Name,
                    Priority    = item.Priority,
                    StartDate   = item.StartDate,
                    EndDate     = item.EndDate,
                    User        = UserBO.GetById(item.Leader),
                    CreatedDate = item.CreateDate == null ? string.Empty : ((DateTime)item.CreateDate).ToString(Helper.FormatDate),
                };

                if (CurrentUser.IsManager || CurrentUser.DepartmentLeader == item.Leader)
                {
                    listTasks.Add(model);
                }
            }
            searchModel.Tasks = listTasks;
            return(View(searchModel));
        }