public ActionResult LinkUserAndFacility(UserAndFacilityLinkVM model) { int userId = 0; int facilityId = 0; userId = model.SelectedUserNameId; facilityId = model.SelectedFacilityId; if (userId == 0 || facilityId == 0) { return(View("LinkUserAndFacility")); } else { try { using (watermentdbEntities db = new watermentdbEntities()) { var facility = (from x in db.facilities where x.Id == facilityId select x).First(); facility.User_Id = userId; // call SaveChanges db.SaveChanges(); return(RedirectToAction("UserFacility")); } } catch (Exception) { return(RedirectToAction("UserFacility")); throw; } } }
public ActionResult CreateEquipment(EquipmentAddVM model) { if (!ModelState.IsValid) { return(View("CreateEquipment", model)); } else { using (watermentdbEntities db = new watermentdbEntities()) { db.equipments.Add(new equipments { Tag = model.Tag, SIUnits = model.SIUnits, Description = model.Description, LastCalibrated = model.LastCalibrated, InstallDate = model.InstallDate, TypeSpecification = model.TypeSpecification, Manufacturer = model.Manufacturer, facilities_Id = model.facilities_Id }); db.SaveChanges(); ModelState.Clear(); } return(RedirectToAction("Index", new { id = model.facilities_Id })); // var db = new watermentdbEntities(); //Need to create some error handling here. } }
// GET: Equipment with their measurred values. public ActionResult Index(int?id) { //dbcontect class watermentdbEntities db = new watermentdbEntities(); // to hold list of Customer and order details List <EquipmentVM> facilityEquipmentVM = new List <EquipmentVM>(); var equipmentlist = (from Eq in db.equipments.Where(x => x.facilities_Id == id) select new { Eq.Id, Eq.Tag, Eq.SIUnits, Eq.Description, Eq.LastCalibrated, Eq.InstallDate, Eq.Manufacturer, Eq.TypeSpecification, Eq.facilities_Id }).ToList(); //query getting data from database from joining two tables and storing data in customerlist foreach (var item in equipmentlist) { EquipmentVM fevm = new EquipmentVM(); // ViewModel fevm.Tag = item.Tag; fevm.SIUnits = item.SIUnits; fevm.Description = item.Description; fevm.LastCalibrated = item.LastCalibrated; fevm.InstallDate = item.InstallDate; fevm.Manufacturer = item.Manufacturer; fevm.TypeSpecification = item.TypeSpecification; fevm.facilities_Id = item.facilities_Id; facilityEquipmentVM.Add(fevm); } //Using foreach loop fill data from custmerlist to List<CustomerVM>. return(View(facilityEquipmentVM)); //List of CustomerVM (ViewModel) }
public ActionResult DeleteConfirmed(int id) { watermentdbEntities wdbe = new watermentdbEntities(); equipments evm = wdbe.equipments.Find(id); wdbe.equipments.Remove(evm); wdbe.SaveChanges(); return(RedirectToAction("Details")); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await UserManager.FindAsync(model.Email, model.Password); if (user != null) { ///Checks to see if not normal user if (await UserManager.IsInRoleAsync(user.Id, "Admin") || await UserManager.IsInRoleAsync(user.Id, "SuperUser") || await UserManager.IsInRoleAsync(user.Id, "Maintenance")) { await SignInAsync(user, model.RememberMe); return(RedirectToLocal(returnUrl)); } if (await UserManager.IsInRoleAsync(user.Id, "User")) { using (watermentdbEntities context = new watermentdbEntities()) { //Try to find the facility of user try { var facilityId = (from f in context.facilities where f.User_Id == (user.Id) select f).SingleOrDefault(); int userDestination = facilityId.Id; await SignInAsync(user, model.RememberMe); return(RedirectToAction("FacilityDetails", "Facility", new { id = userDestination })); } //If user does not belong to facility, redirect to site regarding not having access yet catch (System.Exception) { throw; } } } //Not registrated else { ModelState.AddModelError("", "Invalid username or password."); } } ModelState.AddModelError("", "Invalid username or password."); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult LinkUserAndFacility() { using (watermentdbEntities context = new watermentdbEntities()) { SelectList UserList = new SelectList(context.User.ToList(), "Id", "UserName"); SelectList FacilityList = new SelectList(context.facilities.Where(x => x.User_Id == null).ToList(), "Id", "Name"); ViewData["Users"] = UserList; ViewData["Facilities"] = FacilityList; ViewData.Model = new UserAndFacilityLinkVM(); return(View()); } //ViewBag.Facility = new SelectList(context.facilities.ToList(), "Name", "Name"); //ViewBag.Users = new SelectList(context.User.ToList(), "UserName", "UserName"); //return View(); }
public ActionResult Delete(int?id) { watermentdbEntities db = new watermentdbEntities(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } equipments eq = db.equipments.Find(id); if (eq == null) { return(HttpNotFound()); } return(View(eq)); }
public ActionResult CreateEquipment(int id) { try { using (watermentdbEntities context = new watermentdbEntities()) { //Imprort the list of facilities. Should just be one, so could have made this a simple object. //This is made to make sure the equipment is added to the proper facility. SelectList FacilityList = new SelectList(context.facilities.Where(x => x.Id == id).ToList(), "Id", "Name"); //This view data string may be called in the view ViewData["Facilities"] = FacilityList; ViewData.Model = new EquipmentAddVM(); return(View()); } } catch (Exception) { ModelState.AddModelError("", "The creation was not sucessful."); throw; } }
public ActionResult UserFacility() { try { using (watermentdbEntities context = new watermentdbEntities()) { List <UserAndFacilityVM> uafvmReturn = new List <UserAndFacilityVM>(); var result = ( from a in context.User join b in context.facilities on a.Id equals b.User_Id select new { uId = a.Id, a.UserName, b.Id, b.Name, b.SerialNumber }).ToList(); foreach (var item in result) { UserAndFacilityVM uafvm = new UserAndFacilityVM(); // ViewModel uafvm.UserId = item.uId; uafvm.UserName = item.UserName; uafvm.FacilityId = item.Id; uafvm.FacilityName = item.Name; uafvm.SerialNumber = item.SerialNumber; uafvmReturn.Add(uafvm); } //Using foreach loop fill data from custmerlist to List<CustomerVM>. return(View(uafvmReturn)); } } catch (Exception) { throw; } }
public ActionResult Index() { watermentdbEntities context = new watermentdbEntities(); List <UsersAndRolesVM> fevmReturn = new List <UsersAndRolesVM>(); var userrolelist = (from u in context.User join ur in context.UserRole on u.Id equals ur.UserId join r in context.Role on ur.RoleId equals r.Id orderby u.Id select new { u.Id, u.UserName, rId = r.Id, r.Name }).ToList(); foreach (var item in userrolelist) { UsersAndRolesVM fevm = new UsersAndRolesVM(); // ViewModel fevm.UserId = item.Id; fevm.UserName = item.UserName; fevm.RoleName = item.Name; fevmReturn.Add(fevm); } //Using foreach loop fill data from custmerlist to List<CustomerVM>. return(View(fevmReturn)); }