예제 #1
0
        public ActionResult EditHead(int LabHeadId)
        {
            var x = (from y in con.Laboratory_Head
                     where y.Laboratory_HeadId == LabHeadId
                     select y).FirstOrDefault();

            ViewBag.LabHeadInfo = x.Laboratory_HeadId;


            itmmAdminHead a = new itmmAdminHead();

            a.fname = x.FirstName;
            a.lname = x.LastName;
            a.cnum  = x.ContactNum;
            a.eadd  = x.EmailAdd;

            // get all labs
            var b = from y in con.Laboratories
                    where y.inactive == 0
                    select y;

            ViewBag.LabList = b;


            return(View(a));
        }
예제 #2
0
        public ActionResult Head(itmmAdminHead model, int section)
        {
            var l = from y in con.Laboratories
                    orderby y.LaboratoryName ascending
                    select y;

            ViewBag.LabList = l;

            var b = from y in con.Laboratory_Head
                    select y;

            ViewBag.HeadList = b;

            if (ModelState.IsValid)
            {
                AccountMembershipService MembershipService = new AccountMembershipService();
                MembershipCreateStatus   createStatus      = MembershipService.CreateUser(model.uname, model.password, model.eadd);
                if (createStatus == MembershipCreateStatus.Success)
                {
                    Roles.AddUserToRole(model.uname, "Head");
                    Laboratory_Head a = new Laboratory_Head();
                    a.FirstName    = model.fname;
                    a.LastName     = model.lname;
                    a.UserName     = model.uname;
                    a.ContactNum   = model.cnum;
                    a.EmailAdd     = model.eadd;
                    a.LaboratoryId = section;

                    var x = (from y in con.Laboratories
                             where y.LaboratoryId == section
                             select y).FirstOrDefault();

                    x.UserName = model.uname;

                    con.AddToLaboratory_Head(a);

                    con.SaveChanges();


                    return(RedirectToAction("Head", "Admin"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            return(View(model));
        }
예제 #3
0
        public ActionResult EditHead(itmmAdminHead model, int LabHeadId, int section)
        {
            var x = (from y in con.Laboratory_Head
                     where y.Laboratory_HeadId == LabHeadId
                     select y).FirstOrDefault();

            x.FirstName              = model.fname;
            x.LastName               = model.lname;
            x.ContactNum             = model.cnum;
            x.EmailAdd               = model.eadd;
            x.LaboratoryId           = section;
            x.Laboratory.DateUpdated = DateTime.Now;

            // unassign head to its previous lab
            var b = from y in con.Laboratories
                    where y.UserName == x.UserName
                    select y;

            if (b != null)
            {
                foreach (var item in b)
                {
                    item.UserName = null;
                }
            }

            // assign head to lab
            var z = (from y in con.Laboratories
                     where y.LaboratoryId == section
                     select y).FirstOrDefault();

            z.UserName = x.UserName;

            con.SaveChanges();

            return(RedirectToAction("Head", "AdminBold"));
        }