Beispiel #1
0
        public ActionResult _UploadFile(HttpPostedFileBase upload)
        {
            try
            {
                user = db.Users.Where(e => e.UserPseudonym == User.Identity.Name).First();
                if (upload != null && upload.ContentLength > 0)
                {
                    AvatarFile avatar = new AvatarFile
                    {
                        ContentType = upload.ContentType
                    };
                    using (var reader = new BinaryReader(upload.InputStream))
                    {
                        avatar.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    user.Avatar = avatar;
                }
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                TempData["Status"] = "Avater has been added!";
            }
            catch (Exception e)
            {
                TempData["Status"] = "An error occured!";
            }

            return RedirectToAction("Profile");
        }
Beispiel #2
0
        public ActionResult _AddItem(ShopItem shopItem, HttpPostedFileBase upload)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    user = db.Users.Where(e => e.UserPseudonym == User.Identity.Name).First();
                    if (upload != null && upload.ContentLength > 0)
                    {
                        AvatarFile img = new AvatarFile
                        {
                            ContentType = upload.ContentType
                        };
                        using (var reader = new BinaryReader(upload.InputStream))
                        {
                            img.Content = reader.ReadBytes(upload.ContentLength);
                        }
                        shopItem.Img = img;
                    }
                    db.ShopItems.Add(shopItem);
                    db.SaveChanges();
                    TempData["Status"] = "Item successfully added.";
                }

            }
            catch (Exception e)
            {
                TempData["Status"] = "An error occured!";
            }
            ViewBag.ListOfType = constans.GetTypes();
            return View();
        }