示例#1
0
        public ItemViewModel Update(AdminUpdateItemViewModel item)
        {
            if (item == null || item.ItemId < 1)
                return null;

            var itemToUpdate = AssignItemToUpdate(item);

            return itemToUpdate;
        }
        public ActionResult Update(AdminUpdateItemViewModel item)
        {
            try
            {
                if (User.IsInRole("Admin"))
                {
                    if (item == null || item.ItemId < 1)
                        return null;

                    var itemToUpdate = _repo.Update(item);
                    if (itemToUpdate == null || itemToUpdate.ItemId < 1)
                        return RedirectToAction("Home", "Error404");

                    return RedirectToAction("AdminItem", "Retrieve");
                }
                return RedirectToAction("Login", "Account");
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString());
            }
        }
示例#3
0
        private AdminUpdateItemViewModel AssignItemDetailsForUpdate(ItemViewModel record)
        {
            if (record == null || record.ItemId < 1)
                return null;

            var itemToUpdate = new AdminUpdateItemViewModel()
            {
                ItemId = record.ItemId,
                ProductId = record.ProductId,
                ItemDescription = record.Description,
                DtUpdated = DateTime.UtcNow
            };

            if (itemToUpdate == null)
                return null;

            return itemToUpdate;
        }
示例#4
0
        private ItemViewModel AssignItemToUpdate(AdminUpdateItemViewModel item)
        {
            if (item == null)
                return null;

            var itemToUpdate = db.Items.Where(x => x.ItemId == item.ItemId).FirstOrDefault();
            if (itemToUpdate == null || itemToUpdate.ItemId < 1)
                return null;

            itemToUpdate.ProductId = item.ProductId;
            itemToUpdate.Description = item.ItemDescription;
            itemToUpdate.DtUpdated = item.DtUpdated;

            db.SaveChanges();

            return itemToUpdate;
        }