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)); } }
/// <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; } }
//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()));; } }
/// <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; } }