Exemplo n.º 1
0
        public bool ChangeStatusUser(string id, int roleId)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var com = database.Organization.SingleOrDefault(x => x.ID == id);

            if (com.Status == true)
            {
                var listPerson = database.Person.Where(x => x.SchoolID == id && x.RoleID == roleId).ToList();
                if (listPerson != null)
                {
                    foreach (var item in listPerson)
                    {
                        var model = database.Users.SingleOrDefault(a => a.PersonID == item.PersonID);
                        if (model.Status == true)
                        {
                            model.Status = false;
                            database.SaveChanges();
                        }
                    }
                }
                com.Status = false;
            }
            else
            {
                com.Status = true;
            }
            database.SaveChanges();
            return(com.Status);
        }
Exemplo n.º 2
0
        //Xóa Row IntershipWithTask có TaskId = id
        public void DeleteIntershipWithTask(int id)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            // Tìm IntershipWithTask theo id
            var model = database.IntershipWithTask.Find(id);
            // lưu các biến internshipId , sort
            var internshipId = model.InternshipID;
            var sort         = model.Sort;
            // tìm IntershipWithTask cuối cùng trong table IntershipWithTask
            var count    = database.IntershipWithTask.ToList().Count();
            var modelend = database.IntershipWithTask.Find(count);

            //Gán các giá trị của modelend vào model
            model.InternshipID = modelend.InternshipID;
            model.TaskID       = modelend.TaskID;
            model.Sort         = modelend.Sort;
            //Remove modelend
            database.IntershipWithTask.Remove(modelend);
            database.SaveChanges();
            //lấy listIntershipWithTask dựa trên internshipId
            var listIntershipWithTask = database.IntershipWithTask.Where(x => x.InternshipID == internshipId).OrderBy(c => c.Sort).ToList();

            // Update sort trong listIntershipWithTask
            foreach (var item in listIntershipWithTask)
            {
                if (item.Sort > sort)
                {
                    item.Sort = item.Sort - 1;
                    database.SaveChanges();
                }
            }
        }
Exemplo n.º 3
0
        public void ChangeStatusInternShip(string id, bool status)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var list = new List <InternShip>();
            var date = DateTime.Now;

            if (status == false)
            {
                list = database.InternShip.Where(x => x.PersonID == id && x.Status == true).ToList();
                foreach (var item in list)
                {
                    item.Status = false;
                }
                database.SaveChanges();
            }
            else
            {
                list = database.InternShip.Where(x => x.PersonID == id).ToList();
                foreach (var item in list)
                {
                    if (item.StartDay > date)
                    {
                        item.Status = false;
                    }
                    else if (item.StartDay.AddMonths(item.ExpiryDate) > date)
                    {
                        item.Status = true;
                    }
                }
                database.SaveChanges();
            }
        }
        public void deleteInternShip(int id)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var count    = database.InternShip.ToList().Count();
            var modelend = database.InternShip.SingleOrDefault(x => x.InternshipID == count);
            var model    = database.InternShip.SingleOrDefault(c => c.InternshipID == id);

            model.CourseName = modelend.CourseName;
            model.Note       = modelend.Note;
            model.PersonID   = modelend.PersonID;
            model.CompanyID  = modelend.CompanyID;
            model.StartDay   = modelend.StartDay;
            model.ExpiryDate = modelend.ExpiryDate;
            model.Status     = modelend.Status;
            var list = database.IntershipWithTask.Where(a => a.InternshipID == count).ToList();

            if (list != null)
            {
                foreach (var item in list)
                {
                    database.IntershipWithTask.Find(item.ID).InternshipID = id;
                }
                database.SaveChanges();
            }
            database.InternShip.Remove(modelend);
            database.SaveChanges();
        }
Exemplo n.º 5
0
 public bool Extension(string id, int val)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         var list = database.Organization.Where(x => x.PersonID == id).ToList();
         foreach (var item in list)
         {
             if (item.Status == true)
             {
                 item.ExpiryDate += +val;
             }
             else
             {
                 item.StartDay   = DateTime.Now;
                 item.ExpiryDate = val;
                 item.SendEmail  = false;
                 new Share().ChangeStatus(id, 2);
             }
             database.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 6
0
 public bool DeleteQuestion(int id)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         //Đếm table quesition có báo nhiêu row
         var count = database.Question.ToList().Count;
         // kiểm tra count và id có bằng nhau không
         if (count == id)
         {
             database.Question.Remove(database.Question.Find(id));
         }
         else
         {
             var modelend = database.Question.Find(count);
             // Tìm model
             var model = database.Question.Find(id);
             // remove model đối đối tượng chứ không phải remove id
             model.TaskID  = modelend.TaskID;
             model.Content = modelend.Content;
             model.Answer  = modelend.Answer;
             model.A       = modelend.A;
             model.B       = modelend.B;
             model.C       = modelend.C;
             model.D       = modelend.D;
             database.Question.Remove(modelend);
         }
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public bool ChangeStatusInternS(int id)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var com = database.InternShip.Find(id);

            if (com.Status == true)
            {
                com.Status = false;
            }
            else
            {
                var date = DateTime.Now;
                if (com.StartDay > date)
                {
                    com.StartDay = date;
                    com.Status   = true;
                }
                else if (com.StartDay.AddMonths(com.ExpiryDate) > date)
                {
                    com.Status = true;
                }
            }
            database.SaveChanges();
            return(com.Status);
        }
Exemplo n.º 8
0
        public void InsertInt(Intern intern)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();

            database.Intern.Add(intern);
            database.SaveChanges();
        }
Exemplo n.º 9
0
 public bool UpdateIntern(string schoolId, string newSchoolID)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         var listIntern = database.Person.Where(x => x.SchoolID == schoolId && x.RoleID == 5).ToList();
         if (listIntern != null)
         {
             if (newSchoolID != null)
             {
                 foreach (var item in listIntern)
                 {
                     item.SchoolID = newSchoolID;
                 }
             }
             else
             {
                 foreach (var item in listIntern)
                 {
                     item.SchoolID = null;
                 }
             }
             database.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
 public bool CreateInternShip(InternShip ish)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         InternShip          i        = new InternShip();
         i.InternshipID = database.InternShip.Count() + 1;
         i.CourseName   = ish.CourseName;
         i.Note         = ish.Note;
         i.StartDay     = ish.StartDay;
         i.ExpiryDate   = ish.ExpiryDate;
         i.Status       = false;
         i.CompanyID    = Session["CompanyID"].ToString();
         var ro = Convert.ToInt32(Session["Role"]);
         if (ish.PersonID != null)
         {
             i.PersonID = ish.PersonID;
         }
         else if (ro == 4)
         {
             var pid = Session["Person"].ToString();
             i.PersonID = pid;
         }
         database.InternShip.Add(i);
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 11
0
        public ActionResult CreateUser(Users user)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var findU = database.Users.Find(user.UserName);

            if (findU != null)
            {
                ModelState.AddModelError("", "UserName đã tồn tại");
            }
            else
            {
                var findP = database.Person.Find(user.PersonID);
                if (findP == null)
                {
                    ModelState.AddModelError("", "Sai mã xác nhận");
                }
                else
                {
                    Users tk = new Users();
                    tk.UserName = user.UserName;
                    tk.PassWord = MaHoaMd5.MD5Hash(user.PassWord);
                    tk.PersonID = user.PersonID;
                    tk.Status   = true;
                    database.Users.Add(tk);
                    database.SaveChanges();
                    ModelState.AddModelError("", "Đăng ký thành công");
                }
            }
            return(View("CreateUser"));
        }
Exemplo n.º 12
0
        //Xóa 1 bài học
        public int DeleteTask(int id)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            Company             company  = new Company();

            if (company.DeleteListQuestion(id) == true && company.DeleteListIntershipWithTask(id, 0) == true)
            {
                database.Task.Remove(database.Task.Find(id));
                database.SaveChanges();
                return(1);
            }
            else
            {
                if (company.DeleteListQuestion(id) == false)
                {
                    return(2);
                }
                else
                {
                    if (company.DeleteListIntershipWithTask(id, 0) == false)
                    {
                        return(3);
                    }
                    else
                    {
                        return(4);
                    }
                }
            }
        }
Exemplo n.º 13
0
        public ActionResult Delete(string id)
        {
            JsonSerializerSettings json = new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };
            var result = "";

            switch (DeleteFaculty(id))
            {
            case 1:
                WebDatabaseEntities database = new WebDatabaseEntities();
                var model = database.Organization.Find(id);
                database.Organization.Remove(model);
                database.SaveChanges();
                result = JsonConvert.SerializeObject("Xóa thành công", Formatting.Indented, json);
                break;

            case 2:
                result = JsonConvert.SerializeObject("Không thể xóa Giáo vụ", Formatting.Indented, json);
                break;

            case 3:
                result = JsonConvert.SerializeObject("Không thể câp nhật thực tập sinh", Formatting.Indented, json);
                break;
            }
            return(this.Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 14
0
        public void UpdateUser(string personID, string newPass)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var model = database.Users.SingleOrDefault(x => x.PersonID == personID);

            model.PassWord = MaHoaMd5.MD5Hash(newPass);
            database.SaveChanges();
        }
Exemplo n.º 15
0
        public bool UpdateOrganization(Organization organization, int roileId)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var model = database.Organization.SingleOrDefault(x => x.ID == organization.ID);

            //roileId = 1 là Faculty
            if (roileId == 1)
            {
                try
                {
                    model.Name  = organization.Name;
                    model.Phone = organization.Phone;
                    model.Fax   = organization.Fax;
                    model.Email = organization.Email;
                    database.SaveChanges();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    model.Name    = organization.Name;
                    model.Address = organization.Address;
                    model.Phone   = organization.Phone;
                    model.Fax     = organization.Fax;
                    model.Image   = organization.Image;
                    model.Logo    = organization.Logo;
                    model.Note    = organization.Note;
                    model.Email   = organization.Email;
                    database.SaveChanges();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
        public ActionResult Accuracy(int id)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var pid   = Session["Person"].ToString();
            var model = database.InternShip.Find(id);

            model.PersonID = pid;
            database.SaveChanges();
            return(RedirectToAction("Index", new { id = 0 }));
        }
Exemplo n.º 17
0
 //Xóa 1 người
 public bool DeletePerson(string id)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         var userName = database.Users.SingleOrDefault(c => c.PersonID == id);
         if (userName != null)
         {
             database.Users.Remove(userName);
             database.SaveChanges();
         }
         var model = database.Person.Find(id);
         database.Person.Remove(model);
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 18
0
        public ActionResult Edit(InternClass intern)
        {
            var role = Convert.ToInt32(Session["Role"].ToString());

            if (ModelState.IsValid)
            {
                WebDatabaseEntities database = new WebDatabaseEntities();
                var model = database.Person.Find(intern.PersonID);
                model.LastName  = intern.LastName;
                model.FirstName = intern.FirstName;
                model.Birthday  = intern.Birthday;
                model.Gender    = intern.Gender;
                model.Address   = intern.Address;
                model.Phone     = intern.Phone;
                var email = model.Email;
                model.Email = intern.Email;
                model.Image = intern.Image;
                if (role == 3 || role == 6)
                {
                    if (intern.CompanyID != null)
                    {
                        model.CompanyID = intern.CompanyID;
                    }
                    UpdateIntern(intern.PersonID, intern.StudentCode);
                }
                else
                {
                    if (intern.FacultyId != null)
                    {
                        model.SchoolID = intern.FacultyId;
                    }
                }
                database.SaveChanges();
                if (email != intern.Email)
                {
                    SendMailTK(intern.PersonID);
                }

                ModelState.AddModelError("", "Cập nhật Thực tập sinh thành công");
            }
            else
            {
                ModelState.AddModelError("", "Cập nhật Thực tập sinh thất bại");
            }
            SetViewBag();
            SetViewBagS();
            SetViewBagG();
            if (role != 3)
            {
                SetViewBagI();
            }
            return(View("Edit"));
        }
Exemplo n.º 19
0
        public void checkOrgan()
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            // Lấy ngày hiện tại
            DateTime time       = DateTime.Now;
            var      listPerson = database.Person.Where(x => x.RoleID == 2 || x.RoleID == 6).ToList();
            // Danh sách Cơ quan
            List <Organization> listOrg = new List <Organization>();

            foreach (var model in listPerson)
            {
                var org = database.Organization.Find(model.CompanyID);
                listOrg.Add(org);
            }
            // tạo 2 danh sách mới
            List <Organization> listTimeExpired = new List <Organization>();
            List <Organization> listSendEmail   = new List <Organization>();

            foreach (var item in listOrg)
            {
                // Xác định hạn cuối
                DateTime eDate = item.StartDay.AddMonths(item.ExpiryDate);
                if (eDate >= time)
                {
                    // Tính số ngày còn lại
                    var timespan = eDate - time;
                    // Lấy số  chẳn.
                    double view = Math.Floor(timespan.TotalDays);
                    if (view < 30 && item.SendEmail == false)
                    {
                        listSendEmail.Add(item);
                    }
                }
                else
                {
                    listTimeExpired.Add(item);
                }
            }
            foreach (var item1 in listTimeExpired)
            {
                ChangesStatusOrgan(item1.ID);
            }
            // Gửi Email cho công ty gần tời hạn
            foreach (var item2 in listSendEmail)
            {
                if (Send(item2.ID))
                {
                    database.Organization.Find(item2.ID).SendEmail = true;
                }
            }
            database.SaveChanges();
        }
Exemplo n.º 20
0
 public bool InsertPerson(Person person)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         database.Person.Add(person);
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 21
0
 //cập nhật lại PersonID cho organzation
 public bool UpdatePersonOfOrganzation(string id)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         var model = database.Organization.SingleOrDefault(x => x.ID == id);
         model.PersonID = "ZXCVBNML";
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 22
0
 public bool deleteOrganzation(string id)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         var model = database.Organization.SingleOrDefault(x => x.ID == id);
         database.Organization.Remove(model);
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 23
0
 public bool UpdateIntern(string id, string studentCode)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         var model1 = database.Intern.Find(id);
         model1.StudentCode = studentCode;
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 24
0
        public bool ChangeStatusUser(string id)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var com = database.Users.SingleOrDefault(x => x.PersonID == id);

            if (com.Status == true)
            {
                com.Status = false;
            }
            else
            {
                com.Status = true;
            }
            database.SaveChanges();
            return(com.Status);
        }
Exemplo n.º 25
0
 public bool AddIntern(List <string> listIntern, int id)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         foreach (var i in listIntern)
         {
             database.Intern.Find(i).InternshipID = id;
             database.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 26
0
        public void ChangesStatusOrgan(string id, int role, bool status)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var findP = database.Person.SingleOrDefault(x => x.CompanyID == id && x.RoleID == role);
            var findU = database.Users.SingleOrDefault(x => x.PersonID == findP.PersonID);

            if (findU != null)
            {
                findU.Status = !status;
            }
            database.SaveChanges();
            List <Person> list = new List <Person>();

            if (role == 2)
            {
                list = database.Person.Where(x => x.CompanyID == id && x.RoleID == 4).ToList();
            }
            else
            {
                list = database.Person.Where(x => x.CompanyID == id && x.RoleID == 3).ToList();
            }
            if (list != null)
            {
                if (role == 2)
                {
                    foreach (var item in list)
                    {
                        if (new LeaderController().ChangeStatusLeader(item.PersonID) == status)
                        {
                            new LeaderController().ChangeStatusLeader(item.PersonID);
                        }
                    }
                }
                else
                {
                    foreach (var item in list)
                    {
                        if (ChangeStatusUser(item.PersonID) == status)
                        {
                            ChangeStatusUser(item.PersonID);
                        }
                    }
                }
            }
        }
        public ActionResult UpdateSort(int id, int sort)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var find1 = database.IntershipWithTask.Find(id);
            int sort1 = find1.Sort; //1

            find1.Sort = sort;
            var find2 = database.IntershipWithTask.SingleOrDefault(x => x.InternshipID == find1.InternshipID && x.Sort == sort);

            find2.Sort = sort1;
            database.SaveChanges();
            JsonSerializerSettings json = new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };
            var result = JsonConvert.SerializeObject("Cập nhật danh sách bài học thành công", Formatting.Indented, json);

            return(this.Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 28
0
        // Caaph nhật trrangj thái của công ty
        public bool ChangeStatus(string id, int role)
        {
            WebDatabaseEntities database = new WebDatabaseEntities();
            var com = database.Organization.Find(id);

            if (com.Status == true)
            {
                ChangesStatusOrgan(id, role, true);
                com.Status = false;
            }
            else
            {
                ChangesStatusOrgan(id, role, false);
                com.Status = true;
            }
            database.SaveChanges();
            return(com.Status);
        }
Exemplo n.º 29
0
 public bool updateInternShip(string id, string idnew)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         var list = database.InternShip.Where(x => x.PersonID == id).ToList();
         foreach (var item in list)
         {
             database.InternShip.Find(item.InternshipID).PersonID = idnew;
             database.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 30
0
 public bool updateTask(string id, string idnew)
 {
     try
     {
         WebDatabaseEntities database = new WebDatabaseEntities();
         var listQ = database.Task.Where(x => x.PersonID == id);
         foreach (var item in listQ)
         {
             database.Task.Find(item.TaskID).PersonID = idnew;
         }
         database.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }