コード例 #1
0
        public ActionResult Create(SportInv ap, HttpPostedFileBase imageUpload = null)
        {
            if (ModelState.IsValid)
            {
                if (imageUpload != null)
                {
                    var count = imageUpload.ContentLength;
                    ap.Image = new byte[count];
                    imageUpload.InputStream.Read(ap.Image, 0, (int)count);
                    ap.MimeType = imageUpload.ContentType;
                }
                try
                {
                    repository.CreateSportInv(ap);

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    //return View(ap);
                    return(View());
                }
            }
            else
            {
                return(View(ap));
            }
        }
コード例 #2
0
ファイル: Cart.cs プロジェクト: woodlik/LabMVC
        /// <summary>
        /// Удалить из корзины
        /// </summary>
        /// <param name="SportInv">Объект для удаления</param>
        public void RemoveItem(SportInv SportInv)
        {
            var item = items.Find(i => i.SportInv.SportInvId == SportInv.SportInvId);

            if (item.quantity == 1)
            {
                items.Remove(item);
            }
            else
            {
                item.quantity -= 1;
            }
        }
コード例 #3
0
ファイル: SportInvController.cs プロジェクト: woodlik/LabMVC
        //public FileContentResult GetImage(int SportInvId)
        //{
        //    SportInv ap = repository.GetSportInv(SportInvId);

        //    if (ap != null && ap.Image != null)
        //        return File(ap.Image, ap.MimeType);
        //    else
        //    {
        //        return File(imageToView, type.ToString()); ;
        //    }
        //}

        public async Task <FileContentResult> GetImage(int SportInvId)
        {
            SportInv ap = await repository.GetSportInvAsync(SportInvId);

            if (ap != null && ap.Image != null)
            {
                return(File(ap.Image, ap.MimeType));
            }
            else
            {
                return(File(imageToView, type.ToString()));;
            }
        }
コード例 #4
0
ファイル: Cart.cs プロジェクト: woodlik/LabMVC
        /// <summary>
        /// Добавить в корзину
        /// </summary>
        /// <param name="SportInv">объект для добавления</param>
        public void AddItem(SportInv SportInv)
        {
            var item = items.Find(i => i.SportInv.SportInvId == SportInv.SportInvId);

            if (item == null)
            {
                items.Add(new CartItem {
                    SportInv = SportInv, quantity = 1
                });
            }
            else
            {
                item.quantity += 1;
            }
        }