public JsonResult AcceptRequest(int projectID, Guid userID, string email)
        {
            var check = new ProjectMemberDao().Accept(projectID, userID);

            if (!check)
            {
                return(Json(new
                {
                    status = false
                }));
            }
            try
            {
                var    project = new ProjectDao().FindByID(projectID);
                string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/Client/Template/SendAcceptProject.html"));
                content = content.Replace("{{NameProject}}", project.Title);
                new MailHelper().SendMail(email, "Thông báo tham gia Dự án", content);
                return(Json(new
                {
                    status = true
                }));
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    status = false
                }));
            }
        }
        public JsonResult ReturnListMemberAndRequest(int projectID)
        {
            var listMember = new ProjectMemberDao().ListByProject(projectID);

            if (listMember == null)
            {
                return(Json(new
                {
                    status = false
                }));
            }
            var memberDetail   = new List <User>();
            var memberBirthDay = new List <string>();
            var usDao          = new UserDao();

            foreach (var item in listMember)
            {
                var us = usDao.FindById(item.MemberID);
                memberDetail.Add(us);
                memberBirthDay.Add(us.UserBirthDay.ToString("dd/MM/yyyy"));
            }
            return(Json(new
            {
                status = true,
                listMember = listMember,
                memberDetail = memberDetail,
                memberBirthDay = memberBirthDay
            }));
        }
        public JsonResult SendRequestApply(int projectID, string description, string email)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Json(new
                {
                    status = 0
                }));
            }
            var accID      = int.Parse(User.Identity.Name);
            var acc        = new AccountDao().FindAccountById(accID);
            var listMember = new ProjectMemberDao().ListByProject(projectID);

            if (listMember.Select(x => x.MemberID).Contains(acc.UserId))
            {
                return(Json(new
                {
                    status = -1
                }));
            }
            var projectMember = new ProjectMember();

            projectMember.ProjectID   = projectID;
            projectMember.MemberID    = acc.UserId;
            projectMember.CreateDate  = DateTime.Now;
            projectMember.Status      = "request";
            projectMember.Description = description;
            var check = new ProjectMemberDao().Insert(projectMember);

            if (!check)
            {
                return(Json(new
                {
                    stauts = 0
                }));
            }
            try
            {
                var    user    = new UserDao().FindById(acc.UserId);
                var    project = new ProjectDao().FindByID(projectID);
                string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/Client/Template/SendRequestApply.html"));
                content = content.Replace("{{NameUser}}", user.UserName);
                content = content.Replace("{{NameProject}}", project.Title);
                content = content.Replace("{{Description}}", description);
                new MailHelper().SendMail(email, "Request Apply Dự án", content);
                return(Json(new
                {
                    status = 1,
                }));
            }
            catch (Exception e)
            {
                return(Json(new
                {
                    status = 0,
                }));
            }
        }
        public JsonResult DeleteMember(int projectID, Guid userID)
        {
            var check = new ProjectMemberDao().DeleteByUser(projectID, userID);

            return(Json(new
            {
                status = check
            }));
        }
        /// <summary>
        /// add user la intern tham gia vao project
        /// </summary>
        /// <param name="projectID"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        public JsonResult AddUser(int projectID, int userID)
        {
            ProjectMember result = new ProjectMemberDao().Add(projectID, userID, CommonConstants.INTERN);
            //lay thong tin user vua moi duoc them
            User      dl     = (new UserDao().GetByUserId(result.UserID));
            ArrayList dlsend = new ArrayList();

            dlsend.Add(dl.FullName);
            return(Json(dlsend, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddAndEditProject(FormProject model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Account"));
            }
            var accID   = int.Parse(User.Identity.Name);
            var acc     = new AccountDao().FindAccountById(accID);
            var project = new Project();

            if (model.typeAction == "add")
            {
                project.CreateDate = DateTime.Now;
                project.MasterID   = acc.UserId;
            }
            else
            {
                project.ProjectID = model.saveID;
            }
            project.ProjectMajor = model.major;
            project.Title        = model.title;
            project.Amount       = model.amount;
            project.Apply        = 1;
            project.Description  = model.description;
            var check = -1;

            if (model.typeAction == "add")
            {
                check = new ProjectDao().Insert(project);
                var projectMember = new ProjectMember();
                projectMember.ProjectID  = check;
                projectMember.MemberID   = acc.UserId;
                projectMember.CreateDate = DateTime.Now;
                projectMember.Status     = "master";
                var checkSecond = new ProjectMemberDao().Insert(projectMember);
            }
            else
            {
                var edit = new ProjectDao().Edit(project);
            }
            if (model.skill != null && model.skill.Count != 0)
            {
                var prSkillDao = new ProjectSkillDao();
                foreach (var item in model.skill)
                {
                    var prk = new ProjectSkill();
                    prk.ProjectSkill1 = item;
                    prk.ProjectID     = check != -1 ? check : model.saveID;
                    var echInsert = prSkillDao.Insert(prk);
                }
            }
            return(RedirectToAction("ListProject"));
        }
        public JsonResult Delete(int projectID)
        {
            //lay danh sach user trong bang user voi projectID tren
            List <User> listUser = (new UserDao()).GetAllUserByProjectID(projectID);

            //delete data in table projectmember with projectID
            ProjectMemberDao pm     = new ProjectMemberDao();
            bool             result = pm.DeleteByProjectID(projectID);
            //xoa cac user trong bang user
            bool kq = (new UserDao()).Delete(listUser);

            if (result == true && kq == true)
            {
                return(Json((new ProjectDao()).Delete(projectID)));
            }
            else
            {
                return(Json(-1));
            }
        }