Ejemplo n.º 1
0
        public ActionResult Create(TabletViewModel tabletViewModel)
        {
            if (ModelState.IsValid)
            {
                var tablet = Mapper.Map <Tablet>(tabletViewModel);
                db.Tablets.Add(tablet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tabletViewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(TabletViewModel tabletViewModel)
        {
            if (ModelState.IsValid)
            {
                var tablet = Mapper.Map <Tablet>(tabletViewModel);

                db.Entry(tablet).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(tabletViewModel));
        }
Ejemplo n.º 3
0
        // GET: Tablets/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Tablets"));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            TabletViewModel tablet = db.Tablets.Where(t => t.ID == id).Include(t => t.Repairs).Include(t => t.User).Include(t => t.Location).SingleOrDefault();

            if (tablet == null)
            {
                return(HttpNotFound());
            }
            return(View(tablet));
        }
Ejemplo n.º 4
0
        // GET: Tablets/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Tablets"));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            TabletViewModel tabletViewModel = db.Tablets.Find(id);

            if (tabletViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(tabletViewModel));
        }
Ejemplo n.º 5
0
        public ActionResult Edit(TabletViewModel tabletViewModel)
        {
            Tablet tablet = tabletViewModel;

            try
            {
                if (ModelState.IsValid)
                {
                    //db.Entry(tablet).OriginalValues["RowVersion"]
                    db.Entry(tablet).State = EntityState.Modified;
                    //db.Entry(tablet).OriginalValues["RowVersion"] = tabletViewModel.RowVersion;
                    db.Entry(tablet).Property("CreatedOn").IsModified = false;
                    db.SaveChanges();
                    return(RedirectToAction("Details", new { id = tablet.ID }));
                }
            }
            catch (DbUpdateConcurrencyException ex)
            {
                //This is implemented by a virtue of having "RowVersion" field in our model and database. watch this video for details: https://youtu.be/Gi_kEbc5faQ
                ModelState.AddModelError(string.Empty, $"The record you were trying to update was modified by another user. Please go back and try again. {ex.Message}");
            }
            catch (DataException dex)
            {
                //the database error handling. Well explained in this video: https://youtu.be/aKSTDjxGxhw
                if (dex.InnerException.InnerException.Message.Contains("IX_SerialNo"))
                {
                    ModelState.AddModelError("SerialNo", "Unable to save changes. Serial Number must be unique");
                }
                else if (dex.InnerException.InnerException.Message.Contains("IX_TabletName"))
                {
                    ModelState.AddModelError("TabletName", "Unable to save changes. Tablet Name must be unique");
                }
                else if (dex.InnerException.InnerException.Message.Contains("IX_AssetTag"))
                {
                    ModelState.AddModelError("AssetTag", "Unable to save changes. Asset Tag must be unique");
                }
                else
                {
                    ModelState.AddModelError("", "Database error occured. </br>" + dex.InnerException.InnerException.Message);
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, $"Error occured Copy the error message and send it to Dima</br>: {ex.Message}. + {ex.InnerException.Message} + {ex.InnerException.InnerException.Message}");
            }
            return(View(tabletViewModel));
        }
Ejemplo n.º 6
0
        public ActionResult Create(TabletViewModel tabletViewModel)
        {
            //implicit conversion using implicit operator defined in TabletViewModel Class
            Tablet tablet = tabletViewModel;

            try
            {
                if (ModelState.IsValid)
                {
                    db.Tablets.Add(tablet);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException dex)
            {
                if (dex.InnerException.InnerException.Message.Contains("IX_SerialNo"))
                {
                    ModelState.AddModelError("SerialNo", "Unable to save changes. Serial Number must be unique");
                }
                else if (dex.InnerException.InnerException.Message.Contains("IX_TabletName"))
                {
                    ModelState.AddModelError("TabletName", "Unable to save changes. Tablet Name must be unique");
                }
                else if (dex.InnerException.InnerException.Message.Contains("IX_AssetTag"))
                {
                    ModelState.AddModelError("AssetTag", "Unable to save changes. Asset Tag must be unique");
                }
                else
                {
                    ModelState.AddModelError("", $" Database error occured (please copy the error and contact helpdesk)</br>: {dex.Message}. + {dex.InnerException.Message} + {dex.InnerException.Message}");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, $"Error occured Copy the error message and send it to Dima</br>: {ex.Message}. + {ex.InnerException.Message} + {ex.InnerException.InnerException.Message}");
            }
            return(View(tabletViewModel));
        }
Ejemplo n.º 7
0
        // GET: Tablets/Create
        public ActionResult Create()
        {
            var tabletViewModel = new TabletViewModel();

            return(View(tabletViewModel));
        }