Exemplo n.º 1
0
        public JsonResult Delete([Bind(Include = "Id")] ItemDetailVM toBeRemoved)
        {
            if (toBeRemoved.Id == 0)
            {
                return(Json(new { success = false, ErrorMessage = "Id cannot be zero." }));
            }

            try
            {
                _itemService.Remove(toBeRemoved);
                return(Json(new { success = true }));
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Item not found."))
                {
                    ModelState.AddModelError(string.Empty, "The delete failed because the item was not found.");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "The delete failed.");
                }

                return(JsonErrorResult());
            }
        }
        // GET: Item/Details/5
        // GET: Item/Details/{id}
        public ActionResult Details(int?id)
        {
            List <CustomField> CustomFields;
            ItemDetailVM       ItemDetailVM = new ItemDetailVM();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //retrieve Item by parameter id
            Item item = db.Item.Find(id);

            if (item == null)
            {
                return(HttpNotFound());
            }
            else
            {
                //retrieve CustomField List with CustomFieldValues by ItemID
                CustomFields = db.CustomField
                               .Where(x => x.Items.Any(y => y.ItemID == item.ItemID))
                               .ToList();

                //to carry Item with CustomField List
                ItemDetailVM.ItemID       = item.ItemID;
                ItemDetailVM.ItemName     = item.ItemName;
                ItemDetailVM.ItemPrice    = item.ItemPrice;
                ItemDetailVM.Category     = item.Category;
                ItemDetailVM.Image        = item.Image;
                ItemDetailVM.CustomFields = CustomFields;
            }

            return(View(ItemDetailVM));
        }
Exemplo n.º 3
0
        public ItemDetailPage(Item selectedItem)
        {
            InitializeComponent();
            SelectedItem   = selectedItem;
            viewModel      = new ItemDetailVM();
            BindingContext = viewModel;

            // When below message is recieved, close page:
            MessagingCenter.Subscribe <App>((App)Application.Current, Constants.CLOSE_ITEM_DETAIL_PAGE, (sender) =>
            {
                Navigation.PopPopupAsync();
            });

            // When below message is recieved, refocus keyboard
            MessagingCenter.Subscribe <App>((App)Application.Current, Constants.REFOCUS_KEYBOARD, (sender) =>
            {
                Thread.Sleep(1000);

                var keyboard = DependencyService.Get <IKeyboardService>();
                keyboard.ShowKeyboard();
            });

            //Navigation.RemovePopupPageAsync(ShoppingListPageUndoPopup);
            //Navigation.RemovePage(ShoppingListPageUndoPopup)
        }
Exemplo n.º 4
0
        public ItemDetailVM GetItemDetails(int id)
        {
            ItemUnitRepo iu   = new ItemUnitRepo();
            ItemDetailVM item = new ItemDetailVM();

            item.Item  = GetItemDetail(id);
            item.Units = iu.GetItemUnitListByItemId(id);
            return(item);
        }
Exemplo n.º 5
0
        public IActionResult ItemPhoto(int id)
        {
            ItemDetailVM VM = new ItemDetailVM();

            int?CompID = HttpContext.Session.GetInt32("CompanyID");
            var data   = _context.Item.Where(r => r.CompanyID == CompID).Where(m => m.ItemID == id).FirstOrDefault();

            byte[] photo = data.PhotoData;
            if (photo != null)
            {
                string imageBase64 = Convert.ToBase64String(photo);
                string imageSrc    = string.Format("data:image/gif;base64,{0}", imageBase64);
                VM.ItemPhoto = imageSrc;
            }
            VM.ItemName       = data.ItemName;
            VM.ItemDetailVMID = data.ItemID;
            VM.Quantity       = data.Quantity;

            return(PartialView(VM));
        }
Exemplo n.º 6
0
 public ActionResult Add([Bind(Include = "Code,Description,UnitsOfMeasure,QtyOnHand")] ItemDetailVM itemVM)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _itemService.Add(itemVM);
             return(Json(new { success = true, model = itemVM }));
         }
         catch (Exception ex)
         {
             if (ex.Message.Contains("IX_Code"))
             {
                 ModelState.AddModelError("Code", "This Item Number already exists. Duplicate Item Numbers are not allowed.");
             }
             else
             {
                 ModelState.AddModelError(string.Empty, "The save failed.");
             }
         }
     }
     return(JsonErrorResult());
 }
Exemplo n.º 7
0
        //public JsonResult Update([Bind(Include = "Id,Code,Description,UnitsOfMeasure,QtyOnHand")]ItemVM revised)
        public JsonResult Update(ItemDetailVM revised)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var updated = _itemService.Update(revised);
                    return(Json(new { success = true, model = updated }));
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("IX_Code"))
                    {
                        ModelState.AddModelError("Code", "This Item Number already exists. Duplicate Item Numbers are not allowed.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "The save failed.");
                    }
                }
            }

            return(JsonErrorResult());
        }
Exemplo n.º 8
0
        public ItemDetailPage(ItemDetailVM viewModel)
        {
            InitializeComponent();

            BindingContext = _viewModel = viewModel;
        }
Exemplo n.º 9
0
 public ClosePopUpCommand(ItemDetailVM itemDetailVM)
 {
     viewModel = itemDetailVM;
 }
Exemplo n.º 10
0
 public UpdateItemCommand(ItemDetailVM itemDetailVM)
 {
     viewModel = itemDetailVM;
 }
Exemplo n.º 11
0
 public DeleteItemCommand(ItemDetailVM itemDetailVM)
 {
     viewModel = itemDetailVM;
 }