Exemplo n.º 1
0
        public ActionResult Create(Staff staff, string customer, string staffs, string process, string order, string store, string finance
            , string customer_edit, string staffs_edit, string process_edit, string order_edit, string store_edit, string finance_edit, HttpPostedFileBase fileImage)
        {
            if (this.Session["Account"] == null)
            {
                return Redirect("/Login");
            }
            if (ModelState.IsValid)
            {
                 Permission per = new Permission();
                 var time = DateTime.Now;
                 staff.CreaterId=Convert.ToInt32(this.Session["ID"]);
                 staff.Invisible = false;
                 staff.Time = time;
                 if (fileImage != null)
                 {
                     fileImage.SaveAs(HttpContext.Server.MapPath("~/img/") + fileImage.FileName);
                     staff.ImageURL = fileImage.FileName;
                 }
                db.Staffs.Add(staff);
                db.SaveChanges();
                Staff newstaff = db.Staffs.Where(s => s.StaffName == staff.StaffName).FirstOrDefault();

                if (customer == "on")
                {
                    per.ModuleId = 1;
                    per.UserId = newstaff.Id;
                    per.Edit = false;
                    if (customer_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (staffs == "on")
                {
                    per.ModuleId = 4;
                    per.UserId = newstaff.Id;
                    per.Edit = false;
                    if (staffs_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (process == "on")
                {
                    per.ModuleId = 6;
                    per.Edit = false;
                    per.UserId = newstaff.Id;
                    if (process_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (order == "on")
                {
                    per.ModuleId = 2;
                    per.UserId = newstaff.Id;
                    per.Edit = false;
                    if (store_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (store == "on")
                {
                    per.ModuleId = 5;
                    per.UserId = newstaff.Id;
                    per.Edit = false;
                    if (store_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (finance == "on")
                {
                    per.ModuleId = 3;
                    per.UserId = newstaff.Id;
                    per.Edit = false;
                    if (finance_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                return RedirectToAction("Index");
            }

            return View(staff);
        }
Exemplo n.º 2
0
        public ActionResult Edit(Staff staff, string customer, string staffs, string process, string order, string store,string finance,
            string customer_edit, string staffs_edit, string process_edit, string order_edit, string store_edit, string finance_edit, HttpPostedFileBase fileImage)
        {
            if (this.Session["Account"] == null)
            {
                return Redirect("/Login");
            }
            Permission per = new Permission();

            ViewBag.ListRole = db.Permissions.Where(s => s.UserId == staff.Id).ToList();
            if (ModelState.IsValid)
            {
                staff.Invisible = false;
                if (fileImage != null)
                {
                    fileImage.SaveAs(HttpContext.Server.MapPath("~/img/") + fileImage.FileName);
                    staff.ImageURL = fileImage.FileName;
                }
                db.Entry(staff).State = EntityState.Modified;
                db.SaveChanges();
                var listPer = db.Permissions.Where(s => s.UserId == staff.Id).ToList();
                for (int i = 0; i < listPer.Count; i++) {
                    db.Permissions.Remove(listPer[i]);
                }

              if (customer == "on")
                {
                    per.Edit = false;
                  per.ModuleId = 1;
                    per.UserId = staff.Id;
                    if (customer_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (staffs == "on")
                {
                    per.Edit = false;
                    per.ModuleId = 4;
                    per.UserId = staff.Id;
                    if (staffs_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (process == "on")
                {
                    per.Edit = false;
                    per.ModuleId = 6;
                    per.UserId = staff.Id;
                    if (process_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (order == "on")
                {

                    per.Edit = false;
                    per.ModuleId = 2;
                    per.UserId = staff.Id;
                    if (order_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (store == "on")
                {
                    per.Edit = false;
                    per.ModuleId = 5;
                    per.UserId = staff.Id;
                    if (store_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }
                if (finance == "on")
                {
                    per.Edit = false;
                    per.ModuleId = 3;
                    per.UserId = staff.Id;

                    if (finance_edit == "on") { per.Edit = true; }
                    db.Permissions.Add(per);
                    db.SaveChanges();
                }

                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(staff);
        }