コード例 #1
0
 public ActionResult CreateRole(TMS_RoleMaster formObj)
 {
     try
     {
         if (formObj.RoleId == 0)
         {
             TMS_RoleMaster obj = new TMS_RoleMaster();
             obj.RoleName   = formObj.RoleName;
             obj.IsActive   = true;
             obj.CreatedBy  = ((TMS_UserMaster)Session["UserDetails"]).UserId;
             obj.CreatedOn  = DateTime.Today;
             obj.ModifiedBy = ((TMS_UserMaster)Session["UserDetails"]).UserId;
             obj.ModifiedOn = DateTime.Today;
             db.TMS_RoleMaster.Add(obj);
             db.SaveChanges();
             TempData["Sussess"] = "Record Inserted Successfully.";
         }
         else
         {
             TMS_RoleMaster obj = db.TMS_RoleMaster.Where(x => x.RoleId == formObj.RoleId).FirstOrDefault();
             obj.RoleName   = formObj.RoleName;
             obj.ModifiedBy = ((TMS_UserMaster)Session["UserDetails"]).UserId;
             obj.ModifiedOn = DateTime.Today;
             db.SaveChanges();
             TempData["Sussess"] = "Role " + formObj.RoleName.ToString() + " updated Successfully.";
         }
     }
     catch (Exception)
     { TempData["Warning"] = "Invalid Request /Validation Error"; }
     return(RedirectToAction("CreateRole"));
 }
コード例 #2
0
        public ActionResult CreateRole(int?id)
        {
            TMS_RoleMaster obj = new TMS_RoleMaster();

            if (id != null)
            {
                obj        = db.TMS_RoleMaster.Where(x => x.RoleId == id).FirstOrDefault();
                ViewBag.id = id;
            }
            ViewBag.List = db.TMS_RoleMaster.Where(x => x.IsActive == true).ToList();
            return(View(obj));
        }