Beispiel #1
0
 public ActionResult EditDisplay([Bind(Include = "HeadsetID,Price,AvailableStoreName,HeadsetName")] VRHeadsetModels vRHeadsetModels)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(vRHeadsetModels).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Unable to save changes. Try again, if the problem persists please contact your systems administrator.");
     }
     return(View(vRHeadsetModels));
 }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "HeadsetID,Price,AvailableStoreID,HeadsetName")] VRHeadsetModels vRHeadsetModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vRHeadsetModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(vRHeadsetModels));
 }
Beispiel #3
0
 public ActionResult Edit([Bind(Include = "BundleID,HeadsetBundledID,BundledItem")] BundlesModels bundlesModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bundlesModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bundlesModels));
 }
 public ActionResult Edit([Bind(Include = "StoreID,StoreName")] StoresModels storesModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(storesModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(storesModels));
 }
Beispiel #5
0
 public ActionResult Edit([Bind(Include = "VehicleID,StudentID,Plate_number,Drivers_License,vehicle_front,vehicle_back,vehicle_side,Make,Color,proof_of_ownership,date_created,last_modified")] Vehicle vehicle)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vehicle).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StudentID = new SelectList(db.Students, "StudentID", "Department", vehicle.StudentID);
     return(View(vehicle));
 }
Beispiel #6
0
 public ActionResult Edit([Bind(Include = "StudentID,name,MatricNumber,StudentImage,ImageText,QrText,Department,Email,date_created,last_modified")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StudentID = new SelectList(db.QRCodes, "StudentID", "StudentID", student.StudentID);
     return(View(student));
 }
Beispiel #7
0
        public bool Update(List <T> dtoList)
        {
            using (var db = new VRContext())
            {
                using (var trans = db.Database.BeginTransaction())
                {
                    T entity = null;
                    try
                    {
                        var dbSet = db.Set <T>();
                        dtoList.ForEach(x =>
                        {
                            entity = dbSet.Find(x.Id);
                            if (entity != null)
                            {
                                db.Entry(entity).CurrentValues.SetValues(x);
                            }
                        });

                        db.SaveChanges();
                        trans.Commit();//Data Saved Successfully. Transaction Commited
                        return(true);
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                            }
                        }
                        return(false);
                    }
                    catch (DbException ex)
                    {
                        Logger.Error(ex.Message, ex);
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();//Error Occured during data saved. Transaction Rolled Back
                        Logger.Error(ex.Message, ex);
                        return(false);
                    }
                }
            }
        }
Beispiel #8
0
        public T Update(T dto)
        {
            T entity = null;

            try
            {
                using (var db = new VRContext())
                {
                    entity = db.Set <T>().Find(dto.Id);
                    if (entity != null)
                    {
                        db.Entry(entity).CurrentValues.SetValues(dto);
                        db.SaveChanges();
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Logger.Error(string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
                entity = null;
            }
            catch (DbException ex)
            {
                Logger.Error(ex.Message, ex);
                entity = null;
            }
            catch (Exception ex)
            {
                entity = null;
                Logger.Error(ex.Message, ex);
            }

            return(entity);
        }