Beispiel #1
0
        public ActionResult additem(HttpPostedFileBase file, HttpPostedFileBase screenshot, Models.Item it)
        {
            Models.Category category = new Models.Category();
                if (file.ContentLength > 0 && it.description != "" && screenshot.ContentLength > 0 && it.title != "" && this.CheckAuth())
                {
                    if (screenshot.ContentType != "image/jpeg" && screenshot.ContentType != "image/png" && screenshot.ContentType != "image/gif")
                    {
                        ViewData["Message"] = "Скриншот должен быть только jpg,gif,png ";

                        ViewData["category"] = category.doSelectCategory();
                        return View("AddItem");
                    }
                    int id_user = Convert.ToInt32(Session["user_id"]);
                    var fileName = Path.GetFileName(file.FileName);

                    var screenname = Path.GetFileName(screenshot.FileName);
                    var path = Path.Combine(Server.MapPath("~/files"), fileName);
                    file.SaveAs(path);
                    path = Path.Combine(Server.MapPath("~/url"), screenname);

                    screenshot.SaveAs(path);
                    string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
                    screenname = baseUrl + "/url/" + screenname;
                    it.doAddItem(it.title, it.description, screenname, it.id_category, id_user, it.value, fileName);

                    //ViewData["Message"] = it.title;
                    ViewData["Message"] = "Товар успешно добавлен";

                    ViewData["category"] = category.doSelectCategory();
                    return View("AddItem");
                }
                ViewData["Message"] = "Вы заполнили не все поля!";

                ViewData["category"] = category.doSelectCategory();
                return View("AddItem");
        }