Esempio n. 1
0
 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.
     }
 }
        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;
                }
            }
        }
Esempio n. 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            watermentdbEntities wdbe = new watermentdbEntities();
            equipments          evm  = wdbe.equipments.Find(id);

            wdbe.equipments.Remove(evm);
            wdbe.SaveChanges();
            return(RedirectToAction("Details"));
        }