Пример #1
0
        public IActionResult CreateItem()
        {
            if (HttpContext.Session.GetString("Username") != "Admin")
            {
                return(RedirectToAction("Index", "Home"));
            }
            ItemCreationViewModel icvm = new ItemCreationViewModel();

            return(View(icvm));
        }
Пример #2
0
 public IActionResult Save(ItemCreationViewModel icvm)
 {
     if (ModelState.IsValid)
     {
         if (icvm.ImageFile.Length <= 0 || !icvm.ImageFile.ContentType.Contains("image"))
         {
             ModelState.AddModelError("ImageFile", "Selected file is not an image.");
             return(View("CreateItem", icvm));
         }
         Item tempitem = ItemToItemVM.ToItem(icvm);
         _ir.Create(tempitem);
         return(RedirectToAction("AllItems", "Item"));
     }
     return(View("CreateItem", icvm));
 }
Пример #3
0
        static public Item ToItem(ItemCreationViewModel icvm)
        {
            MemoryStream memoryStream = new MemoryStream();

            icvm.ImageFile.CopyTo(memoryStream);
            var item = new Item()
            {
                Id        = icvm.Id,
                Name      = icvm.Name,
                ItemType  = (Library.Models.ItemType)icvm.ItemType,
                ImageFile = memoryStream.ToArray()
            };

            return(item);
        }