Exemplo n.º 1
0
        public ActionResult Edit(string id)
        {
            var role = Convert.ToInt32(Session["Role"]);

            SetViewBag();
            SetViewBagS();
            SetViewBagG();
            if (role != 3)
            {
                SetViewBagI();
            }
            WebDatabaseEntities database = new WebDatabaseEntities();
            var         findP            = database.Person.Find(id);
            var         findI            = database.Intern.Find(id);
            InternClass model            = new InternClass();

            model.PersonID    = findP.PersonID;
            model.LastName    = findP.LastName;
            model.FirstName   = findP.FirstName;
            model.Birthday    = findP.Birthday;
            model.Gender      = findP.Gender;
            model.Address     = findP.Address;
            model.Phone       = findP.Phone;
            model.Email       = findP.Email;
            model.Image       = findP.Image;
            model.SchoolID    = findP.SchoolID;
            model.SchoolID    = findP.CompanyID;
            model.StudentCode = findI.StudentCode;
            return(View(model));
        }
Exemplo n.º 2
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.º 3
0
        public ActionResult Create(InternClass per)
        {
            var role = Convert.ToInt32(Session["Role"].ToString());

            if (ModelState.IsValid)
            {
                WebDatabaseEntities database = new WebDatabaseEntities();
                Person person = new Person();
                string personID;
                do
                {
                    personID = new Share().RandomText();
                } while (new Share().FindPerson(personID) == false);
                person.PersonID = personID;
                database.Person.Add(person);
                person.RoleID    = 5;
                person.LastName  = per.LastName;
                person.FirstName = per.FirstName;
                person.Birthday  = per.Birthday;
                person.Gender    = per.Gender;
                person.Address   = per.Address;
                person.Phone     = per.Phone;
                person.Email     = per.Email;


                if (role == 3)
                {
                    var schoolID = Session["SchoolID"].ToString();
                    person.SchoolID  = schoolID;
                    person.CompanyID = per.CompanyID;
                }
                else
                {
                    var companyID = Session["CompanyID"].ToString();
                    person.SchoolID  = per.FacultyId;
                    person.CompanyID = companyID;
                }

                if (new Share().InsertPerson(person))
                {
                    if (SendMailTK(personID))
                    {
                        Intern intern = new Intern();
                        intern.PersonID    = personID;
                        intern.StudentCode = per.StudentCode;
                        if (per.InternshipID != null)
                        {
                            intern.InternshipID = per.InternshipID;
                        }
                        intern.Result = 0;
                        InsertInt(intern);
                        ModelState.AddModelError("", "Thêm Thực tập sinh thành công");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Không thể gửi Email kích hoạt");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Thêm Thực tập sinh thất bại");
                }
            }
            SetViewBag();
            SetViewBagS();
            SetViewBagG();
            if (role != 3)
            {
                SetViewBagI();
            }
            return(View("Create"));
        }