Пример #1
0
        public ActionResult Index(ItemVM item)
        {
            if (!IsAdmin())
            {
                return(Redirect("/"));
            }
            Guid itemId = _itemService.Add(_itemMapper.ConvertFromVM(item)).Id;

            _pictureService.Add(item.Images, itemId);
            return(Redirect("/Admin"));
        }
Пример #2
0
        public ActionResult Create(PictureViewModel pictureViewModel)
        {
            string fileName  = Path.GetFileNameWithoutExtension(pictureViewModel.ImageFile.FileName);
            string extention = Path.GetExtension(pictureViewModel.ImageFile.FileName);

            fileName = fileName + DateTime.Now.ToString("yymmssfff") + extention;
            pictureViewModel.ImagePath = "~/Image/" + fileName;
            fileName = Path.Combine(Server.MapPath("~/Image/"), fileName);
            pictureViewModel.ImageFile.SaveAs(fileName);
            //using (DBContext pc_db = new DBContext())
            //{
            //    var pictureModel = _mapper.Map<PictureModel>(pictureViewModel);
            //    var picModel = _mapper.Map<Picture>(pictureModel);
            //    pc_db.Pictures.Add(picModel);
            //    pc_db.SaveChanges();
            //}
            if (ModelState.IsValid)
            {
                var pictureModel = _mapper.Map <PictureModel>(pictureViewModel);
                _pictureService.Add(pictureModel);
                //ViewBag.ActiveUserRole = GetActiveUserRole();
                return(RedirectToAction("Index"));
            }

            ModelState.Clear();
            return(View());
        }
Пример #3
0
 public ActionResult Create(PictureViewModel model)
 {
     if (ModelState.IsValid)
     {
         var pictureModel = _mapper.Map <PictureModel>(model);
         _pictureService.Add(pictureModel);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Пример #4
0
        public async Task <HttpResponseMessage> Upload()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
            }

            var provider = GetMultipartProvider();
            var result   = await Request.Content.ReadAsMultipartAsync(provider);

            // On upload, files are given a generic name like "BodyPart_26d6abe1-3ae1-416a-9429-b35f15e6e5d5"
            // so this is how you can get the original file name
            var originalFileName = GetDeserializedFileName(result.FileData.First());
            var fileName         = Path.GetFileNameWithoutExtension(originalFileName) + "_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + Path.GetExtension(originalFileName);

            // uploadedFileInfo object will give you some additional stuff like file length,
            // creation time, directory name, a few filesystem methods etc..
            var uploadedFileInfo = new FileInfo(result.FileData.First().LocalFileName);

            // Save Picture
            var fileUploadObj = GetFormData(result);

            fileUploadObj.FileName = fileName;
            var picture = new Picture();

            picture = Mapper.Map(fileUploadObj, picture);
            pictureService.Add(picture);

            // Save file
            string saveFolder = HttpContext.Current.Server.MapPath("~/Images/" + fileUploadObj.PictureType + "/" + PictureSize.Auto + "/");
            string filePath   = Path.Combine(saveFolder, fileName);

            if (!Directory.Exists(saveFolder))
            {
                Directory.CreateDirectory(saveFolder);
            }
            File.Move(uploadedFileInfo.FullName, filePath);
            FileUtil.CreateThumbPicture(filePath, pictureService.GetThumbLocalPath(fileName, ConvertUtil.ToEnum <PictureType>(fileUploadObj.PictureType), PictureSize.Tiny), PictureSize.Tiny);
            FileUtil.CreateThumbPicture(filePath, pictureService.GetThumbLocalPath(fileName, ConvertUtil.ToEnum <PictureType>(fileUploadObj.PictureType), PictureSize.Medium), PictureSize.Medium);

            // Through the request response you can return an object to the Angular controller
            // You will be able to access this in the .success callback through its data attribute
            // If you want to send something to the .error callback, use the HttpStatusCode.BadRequest instead
            return(this.Request.CreateResponse(HttpStatusCode.OK, new { fileName }));
        }
Пример #5
0
        public ActionResult AddBrand(Brand brnd, HttpPostedFileBase fileUpload)
        {
            if (fileUpload != null)
            {
                string path = Path.Combine(Server.MapPath("/Content/AdminUI/images/" + Guid.NewGuid() + "-" + Path.GetFileName(fileUpload.FileName)));
                fileUpload.SaveAs(path);

                Picture picture = new Picture();
                picture.MidPath = path;
                _pictureService.Add(picture);

                Brand brand = new Brand();
                brand.BrandName        = brnd.BrandName;
                brand.BrandDescription = brnd.BrandDescription;
                brand.PictureId        = picture.PictureId;

                _brandService.Add(brand);
            }

            return(RedirectToAction("Index"));
        }
        public virtual async Task <ActionResult> Create(IEnumerable <HttpPostedFileBase> files, long folderId)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/jpg",
                "image/png"
            };
            var httpPostedFileBases = files as HttpPostedFileBase[] ?? files.ToArray();

            if (!httpPostedFileBases.Any())
            {
                ModelState.AddModelError("", "مشکلی در انجام عملیات پیش آمده است");
                return(View());
            }
            foreach (var file in httpPostedFileBases)
            {
                if (file != null && !validImageTypes.Contains(file.ContentType))
                {
                    ModelState.AddModelError("", " پسوند تصویر انتخاب شده غیر مجاز است");
                    return(View());
                }
                if (file == null || file.ContentLength <= 0)
                {
                    continue;
                }
                const string uploadDir = "~/Uploads";
                var          fileName  = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
                var          imagePath = Path.Combine(Server.MapPath(uploadDir), fileName);
                file.SaveAs(imagePath);
                _pictureService.Add(new Picture {
                    Path = fileName, FolderId = folderId
                });
            }
            await _unitOfWork.SaveChangesAsync();

            return(RedirectToAction(MVC.Admin.Folder.ActionNames.Pictures, MVC.Admin.Folder.Name,
                                    new { folderId = folderId }));
        }
Пример #7
0
        public async Task <IActionResult> Post(PictureRequest pictureRequest)
        {
            var response = await _pictureService.Add(pictureRequest);

            return(Ok(response));
        }