public ActionResult Create(JewelryItemsViewModel jewelryItemsViewModel, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                JewelryItems jewelryItems = new JewelryItems();

                var claimsIdentity = User.Identity as ClaimsIdentity;

                UserInfo userInfo = new UserInfo(db);

                Mapper.Map(jewelryItemsViewModel, jewelryItems);
                Companies company = userInfo.getLoggedCompanyId(claimsIdentity);
                jewelryItems.Companies = company;

                db.JewelryItems.Add(jewelryItems);
                db.SaveChanges();

                //save images
                SaveImages(files, company, jewelryItems);

                return(RedirectToAction("Index"));
            }

            return(View(jewelryItemsViewModel));
        }
        // GET: JewelryItems/Create
        public ActionResult Create()
        {
            JewelryItemsViewModel model = new JewelryItemsViewModel();

            model.CompanyList         = new SelectList(db.Companies, "ID", "CompanyName");
            model.CategoryJewelryList = new SelectList(db.JewelryCategories, "ID", "Name");

            return(View(model));
        }
 public ActionResult Edit([Bind(Include = "Id,Weight,Price,Millem,Carat,Pieces,Size,Length,Thick,Wide,Comment,CompanyId,CategoryJewelryId")] JewelryItemsViewModel jewelryItemsViewModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(jewelryItemsViewModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(jewelryItemsViewModel));
 }
        // GET: Order/Details/5
        public ActionResult Details(int id)
        {
            Orders order = db.Orders.Where(x => x.Id == id).ToList().First();

            OrderModel orderModel = new OrderModel();

            foreach (var item in order.OrderJewelryItems)
            {
                JewelryItemsViewModel itemVM = new JewelryItemsViewModel();
                Mapper.Map(item.JewelryItems, itemVM);
                itemVM.Quantity = item.Quantity;
                orderModel.addItem(itemVM);
            }

            return(View(orderModel));
        }
        // GET: JewelryItems/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            JewelryItems jewelryItems = db.JewelryItems.Find(id);

            if (jewelryItems == null)
            {
                return(HttpNotFound());
            }
            JewelryItemsViewModel jewelryItemsViewModel = new JewelryItemsViewModel();

            Mapper.Map(jewelryItems, jewelryItemsViewModel);

            return(View(jewelryItemsViewModel));
        }
        public void addItem(JewelryItemsViewModel item)
        {
            Jewelries.Add(item);
            if (Categories.Where(x => x.Id == item.JewelryCategories.Id).Count() == 0)
            {
                Categories.Add(item.JewelryCategories);
                Weight.Add(item.JewelryCategories.Name, 0);
                Price.Add(item.JewelryCategories.Name, 0);
                Quantity.Add(item.JewelryCategories.Name, 0);
            }
            Weight[item.JewelryCategories.Name]   += item.Weight.Value * item.Quantity;
            Price[item.JewelryCategories.Name]    += item.Price.Value * item.Quantity;
            Quantity[item.JewelryCategories.Name] += item.Quantity;

            Weight["Total"]   += item.Weight.Value * item.Quantity;
            Price["Total"]    += item.Price.Value * item.Quantity;
            Quantity["Total"] += item.Quantity;
        }