public ActionResult Create(int BarberId, HttpPostedFileBase Photo)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var barber = _context.Barbers.Find(BarberId);

            if (barber == null)
            {
                return(HttpNotFound("Service Item yok la"));
            }
            BarberImage barberImage = new BarberImage
            {
                BarberId = BarberId
            };


            if (Photo != null)
            {
                if (!Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Photo type is not valid");

                    return(View());
                }

                barberImage.Image = Photo.SavePhoto("Assets/img", "barberImages");
            }

            _context.BarberImages.Add(barberImage);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public bool NewPackageSubscription(InvestmentCreateModel model, HttpPostedFileBase ReceiptFile, int userId)
        {
            try
            {
                if (ReceiptFile.IsImage())
                {
                    string fileExt     = Path.GetExtension(ReceiptFile.FileName);
                    string newFileName = (DBConstant.UploadReceiptPrefix + DateTime.UtcNow.ConvertToPlainDateTimeString() + Guid.NewGuid().ToString() + fileExt).ToLower();
                    new ImageController().Upload(ConfigurationManager.AppSettings["UploadReceiptPhotoPath"], ReceiptFile, newFileName);

                    var package = _investmentService.GetEntitledPackage(model.Amount);

                    UserPackage up = new UserPackage
                    {
                        PackageId        = package.PackageId,
                        UserId           = userId,
                        TotalAmount      = model.Amount,
                        CreatedTimestamp = DateTime.UtcNow,
                        ReceiptBank      = model.Bank,
                        ReceiptImagePath = newFileName,
                        ReceiptNo        = model.ReferenceNo ?? "",
                        InterestRate     = package.Rate,
                        StatusId         = (int)EStatus.Pending,
                    };

                    _investmentService.InsertUserPackage(up);
                    return(_investmentService.SaveChange(userId));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
            }
            return(false);
        }
        public ActionResult Edit(int ServiceId, HttpPostedFileBase Photo, ServicePortfolio servicePortfolio)
        {
            if (!ModelState.IsValid)
            {
                return(View(servicePortfolio));
            }

            ServicePortfolio servicePortfolioBase = _context.ServicePortfolios.Find(servicePortfolio.Id);

            //var service = _context.Services.Find(ServiceId);
            //if (service == null) return HttpNotFound("Service Item yok la");

            servicePortfolioBase.ServiceId = ServiceId;


            if (Photo != null)
            {
                if (!Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Photo type is not valid");
                    servicePortfolio.Image = servicePortfolioBase.Image;
                    return(View(servicePortfolio));
                }
                RemoveImage("Assets/img/", servicePortfolioBase.Image);
                servicePortfolioBase.Image = Photo.SavePhoto("Assets/img", "servicePortfolios");
            }
            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "ProductGroupID,ProductParentGroupID,ProductGroupTitle")] ProductGroup productGroup, HttpPostedFileBase imgBannerProductGroup, HttpPostedFileBase imgProductGroup)
        {
            if (ModelState.IsValid)
            {
                string mainImagePath   = "/Images/ProuctGroups/MainImage/";
                string bannerImagePath = "/Images/ProuctGroups/BannerImage/";

                if (imgProductGroup != null && imgProductGroup.IsImage())
                {
                    string imageName = Guid.NewGuid() + Path.GetExtension(imgProductGroup.FileName);
                    productGroup.ProductGroupImage = imageName;
                    imgProductGroup.SaveAs(Server.MapPath(mainImagePath + imageName));
                }

                if (imgBannerProductGroup != null && imgBannerProductGroup.IsImage())
                {
                    string imageName = Guid.NewGuid() + Path.GetExtension(imgBannerProductGroup.FileName);
                    productGroup.ProductGroupBanner = imageName;
                    imgBannerProductGroup.SaveAs(Server.MapPath(bannerImagePath + imageName));
                }

                db.ProductGroups.Add(productGroup);
                db.SaveChanges();

                return(PartialView("List", db.ProductGroups.Where(p => p.ProductParentGroupID == null)));
            }

            ViewBag.ProductParentGroupID = new SelectList(db.ProductGroups, "ProductGroupID", "ProductGroupTitle", productGroup.ProductParentGroupID);
            return(PartialView(productGroup));
        }
Ejemplo n.º 5
0
        public ActionResult UploadImageUser(OrderModel orderModel, HttpPostedFileBase file)
        {
            if (file == null || file.ContentLength == 0)
            {
                ModelState.AddModelError("nofile", @"Seleccione una foto.");
            }
            else
            {
                if (file.ContentLength > 1000000 * 5)
                {
                    ModelState.AddModelError("bigfile", @"La foto elegida es muy grande (max = 5 MB).");
                }
                if (!file.IsImage())
                {
                    ModelState.AddModelError("noimage", @"El archivo seleccionado no es una imagen.");
                }
            }
            if (!ModelState.IsValid)
            {
                return(View("ManoImagen", orderModel));
            }

            var fileName = Guid.NewGuid().ToString("N") + ".jpg";
            var fileUrl  = _userFiles.UploadOrderFile(file?.InputStream, fileName);

            TempData["fileUrl"]        = fileUrl.AbsoluteUri;
            TempData["AmputationType"] = orderModel.AmputationType;
            TempData["ProductType"]    = orderModel.ProductType;

            return(Json(new { Action = "ManoMedidas" }));
            //return RedirectToAction("ManoMedidas");
        }
        public ActionResult ProductGroupsParent_Create([DataSourceRequest] DataSourceRequest request, ProductGroupsViewModel productGroupsViewModel,
                                                       HttpPostedFileBase imgProductGroup, HttpPostedFileBase imgProductBanner)
        {
            if (productGroupsViewModel != null && ModelState.IsValid)
            {
                string mainImagePath   = "/Images/ProuctGroups/MainImage/";
                string bannerImagePath = "/Images/ProuctGroups/BannerImage/";
                string imageName       = "";
                string imageNameBanner = "";

                if (imgProductGroup != null && imgProductGroup.IsImage())
                {
                    imageName = Guid.NewGuid() + Path.GetExtension(imgProductGroup.FileName);
                    productGroupsViewModel.ProductGroupImage = imageName;
                    imgProductGroup.SaveAs(Server.MapPath(mainImagePath + imageName));
                }

                if (imgProductBanner != null && imgProductBanner.IsImage())
                {
                    imageNameBanner = Guid.NewGuid() + Path.GetExtension(imgProductBanner.FileName);
                    productGroupsViewModel.ProductGroupBanner = imageNameBanner;
                    imgProductBanner.SaveAs(Server.MapPath(bannerImagePath + imageNameBanner));
                }

                db.ProductGroups.Add(new ProductGroup()
                {
                    ProductGroupTitle  = productGroupsViewModel.ProductGroupTitle,
                    ProductGroupImage  = productGroupsViewModel.ProductGroupImage,
                    ProductGroupBanner = productGroupsViewModel.ProductGroupBanner,
                });
                db.SaveChanges();
            }

            return(Json(new[] { productGroupsViewModel }.ToDataSourceResult(request, ModelState)));
        }
Ejemplo n.º 7
0
        public ActionResult Gallery(AddGalleryViewModel model, HttpPostedFileBase imgUp, int id)
        {
            if (ModelState.IsValid)
            {
                if (imgUp != null && imgUp.IsImage())
                {
                    var gallery = new ProductGalleries
                    {
                        ProductId    = id,
                        GalleryTitle = model.GalleryTitle,
                        ImageName    = Guid.NewGuid() + Path.GetExtension(imgUp.FileName)
                    };

                    imgUp.SaveAs(Server.MapPath("/Images/ProductImages/" + gallery.ImageName));

                    var img = new ImageResizer();
                    img.Resize(Server.MapPath("/Images/ProductImages/" + gallery.ImageName),
                               Server.MapPath("/Images/ProductImages/Resized/" + gallery.ImageName));

                    db.ProductGalleriesRepository.Insert(gallery);
                    db.Save();
                    RedirectToAction("Gallery", new { id = id });
                }
                else
                {
                    return(Redirect("/Admin/Products/Gallery/" + id + "?img=error"));
                }
            }

            return(RedirectToAction("Gallery", new { id = id }));
        }
Ejemplo n.º 8
0
        public ActionResult Create([Bind(Include = "SoftwareId,Title,Description,Text,Visit,CreateDate,ImageName")] Software software
                                   , HttpPostedFileBase imgUp)
        {
            if (ModelState.IsValid)
            {
                if (imgUp != null && imgUp.IsImage())
                {
                    software.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imgUp.FileName);
                    imgUp.SaveAs(Server.MapPath("/Content/Image/Softwares/" + software.ImageName));
                    ImageResizer imageResizer = new ImageResizer();
                    imageResizer.Resize(Server.MapPath("/Content/Image/Softwares/" + software.ImageName),
                                        Server.MapPath("/Content/Image/Softwares/Thumbnail/" + software.ImageName));

                    software.CreateDate = DateTime.Now;
                    software.Visit      = 0;
                    _softwareBusiness.Insert(software);
                    _softwareBusiness.Save();
                    return(RedirectToAction("Index"));
                }

                ViewBag.NewsImage = true;
                return(View(software));
            }

            return(View(software));
        }
        public JsonResult SaveNewUser(Usuarios model, HttpPostedFileBase picture)
        {
            var rh = new ResponseHelper();

            if (picture != null && !picture.IsImage())
            {
                ModelState.AddModelError("Picture", "El archivo adjuntado no es una imagen válida");
            }

            if (!ModelState.IsValid)
            {
                rh.Message = "Ingrese una imagen valida";
            }
            else
            {
                rh = _userService.InsertOrUpdate(model, picture);

                if (rh.Response)
                {
                    rh.Href = "self";
                }
            }

            return(Json(rh));
        }
Ejemplo n.º 10
0
        public ActionResult Edit([Bind(Include = "SlideItemID,SlideID,SlideItemTitle,SlideItemImage,SlideItemLink,SlideItemOrder")] SliderItem sliderItem, HttpPostedFileBase imgSliderItems)
        {
            if (ModelState.IsValid)
            {
                if (imgSliderItems != null && imgSliderItems.IsImage())
                {
                    string imagePath = "/Images/SliderItemImages/";
                    if (sliderItem.SlideItemImage != null)
                    {
                        if (System.IO.File.Exists(Server.MapPath(imagePath + sliderItem.SlideItemImage)))
                        {
                            System.IO.File.Delete(Server.MapPath(imagePath + sliderItem.SlideItemImage));
                        }

                        sliderItem.SlideItemImage = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(imgSliderItems.FileName);
                        imgSliderItems.SaveAs(Server.MapPath(imagePath + sliderItem.SlideItemImage));
                    }
                }

                db.Entry(sliderItem).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SlideID = new SelectList(db.Sliders, "SlideID", "SlideTitle", sliderItem.SlideID);
            return(View(sliderItem));
        }
Ejemplo n.º 11
0
        public ActionResult Create([Bind(Include = "SlideItemID,SlideID,SlideItemTitle,SlideItemImage,SlideItemLink,SlideItemOrder")] SliderItem sliderItem, HttpPostedFileBase imgSliderItems)
        {
            if (ModelState.IsValid)
            {
                if (imgSliderItems != null && imgSliderItems.IsImage())
                {
                    string imagePath = "/Images/SliderItemImages/";

                    sliderItem.SlideItemImage = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(imgSliderItems.FileName);
                    imgSliderItems.SaveAs(Server.MapPath(imagePath + sliderItem.SlideItemImage));

                    db.SliderItems.Add(sliderItem);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                else
                {
                    ModelState.AddModelError("SlideItemImage", "تصویر را انتخاب کنید!");
                    return(View(sliderItem));
                }
            }

            ViewBag.SlideID = new SelectList(db.Sliders, "SlideID", "SlideTitle", sliderItem.SlideID);
            return(View(sliderItem));
        }
Ejemplo n.º 12
0
        private void UpdateOrderFile(OrderModel orderModel, HttpPostedFileBase file, int selectPhoto)
        {
            if (file == null || file.ContentLength == 0)
            {
                ModelState.AddModelError("nofile", @"Seleccione una foto.");
            }
            else
            {
                if (file.ContentLength > 1000000 * 5)
                {
                    ModelState.AddModelError("bigfile", @"La foto elegida es muy grande (max = 5 MB).");
                }
                if (!file.IsImage())
                {
                    ModelState.AddModelError("noimage", @"El archivo seleccionado no es una imagen.");
                }
            }

            var fileName = Guid.NewGuid().ToString("N") + ".jpg";
            var fileUrl  = _userFiles.UploadOrderFile(file?.InputStream, fileName);

            var images = (orderModel.IdImage).Split(',');

            images[selectPhoto] = fileUrl.ToString();

            orderModel.IdImage = String.Join(",", images);

            //Db.OrderModels.AddOrUpdate(orderModel);
            //await Db.SaveChangesAsync();
        }
Ejemplo n.º 13
0
        public ActionResult Create([Bind(Include = "CourseID,CourseName,Price,NumberOfStudents,ShortDescription,CourseLevel,CourseStatus,LastUpdate,ImageName,Text")] Courses courses, List <int> SelectCategory, HttpPostedFileBase ImgUp)
        {
            if (ModelState.IsValid)
            {
                var user = _coursesRepository.GetTeacherForCourses(User.Identity.Name);
                courses.NumberOfStudents = 0;
                courses.LastUpdate       = DateTime.Now;
                courses.UserID           = user.UserID;

                courses.ImageName = "no-image-found.png";
                if (ImgUp != null && ImgUp.IsImage())
                {
                    courses.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(ImgUp.FileName);
                    ImgUp.SaveAs(Server.MapPath("/Images/Courses/" + courses.ImageName));
                }
                foreach (var category in SelectCategory)
                {
                    _selectedCategoryRepository.InsertSelectedCategory(new Selected_Category()
                    {
                        CategoryID = category,
                        CourseID   = courses.CourseID
                    });
                }
                _coursesRepository.InsertCourse(courses);
                _coursesRepository.save();
                ViewBag.Category = _categoryRepository.GetAllCategories().ToList();

                return(View(courses));
            }
            ViewBag.Category = _categoryRepository.GetAllCategories().ToList();
            return(View(courses));
        }
        public ActionResult Create(int ServiceId, HttpPostedFileBase Photo)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var service = _context.Services.Find(ServiceId);

            if (service == null)
            {
                return(HttpNotFound("Service Item yok la"));
            }
            ServicePortfolio servicePortfolio = new ServicePortfolio
            {
                ServiceId = ServiceId
            };


            if (Photo != null)
            {
                if (!Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Photo type is not valid");

                    return(View());
                }

                servicePortfolio.Image = Photo.SavePhoto("Assets/img", "servicePortfolios");
            }

            _context.ServicePortfolios.Add(servicePortfolio);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 15
0
        public ActionResult Create([Bind(Include = "Name,StartingPrice")] AuctionsModel.Auction auction, HttpPostedFileBase image, int?duration)
        {
            auction.ID        = Guid.NewGuid();
            auction.CreatedOn = DateTime.UtcNow;
            auction.State     = "READY";

            if (duration != null)
            {
                auction.Duration = (int)duration;
            }
            else
            {
                auction.Duration = Settings.GlobalSettings.D;
            }

            if (image != null && image.IsImage())
            {
                auction.Image = new byte[image.ContentLength];
                image.InputStream.Read(auction.Image, 0, image.ContentLength);
                //auction.Image = image.CreateThumbnail(150, 150);
            }


            if (ModelState.IsValid)
            {
                db.Auctions.Add(auction);
                db.SaveChanges();
                Logger.Logger.log("auction created, id = " + auction.ID.ToString());
                return(RedirectToAction("Index"));
            }

            return(View(auction));
        }
Ejemplo n.º 16
0
        public ActionResult Edit([Bind(Include = "ProductID,Title,ShortDescription,Text,Price,ImageName,CreateDate")] Products products, List <int> selectedGroups, HttpPostedFileBase imageProduct, string tags)
        {
            if (ModelState.IsValid)
            {
                if (imageProduct != null && imageProduct.IsImage())
                {
                    if (products.ImageName != "images.jpg")
                    {
                        System.IO.File.Delete(Server.MapPath("/Images/ProductImages/" + products.ImageName));
                        System.IO.File.Delete(Server.MapPath("/Images/ProductImages/Thumb/" + products.ImageName));
                    }

                    products.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imageProduct.FileName);
                    imageProduct.SaveAs(Server.MapPath("/Images/ProductImages/" + products.ImageName));
                    ImageResizer img = new ImageResizer();
                    img.Resize(Server.MapPath("/Images/ProductImages/" + products.ImageName),
                               Server.MapPath("/Images/ProductImages/Thumb/" + products.ImageName));
                }
                db.Entry(products).State = EntityState.Modified;


                db.Product_Tags.Where(t => t.ProductID == products.ProductID).ToList().ForEach(t => db.Product_Tags.Remove(t));
                if (!string.IsNullOrEmpty(tags))
                {
                    string[] tag = tags.Split(',');
                    foreach (string t in tag)
                    {
                        db.Product_Tags.Add(new Product_Tags()
                        {
                            ProductID = products.ProductID,
                            Tag       = t.Trim()
                        });
                    }
                }


                db.Prodct_Selected_Groups.Where(g => g.ProductID == products.ProductID).ToList().ForEach(g => db.Prodct_Selected_Groups.Remove(g));
                if (selectedGroups != null && selectedGroups.Any())
                {
                    foreach (int selectedGroup in selectedGroups)
                    {
                        db.Prodct_Selected_Groups.Add(new Prodct_Selected_Groups()
                        {
                            ProductID = products.ProductID,
                            GroupID   = selectedGroup
                        });
                    }
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SelectedGroups = selectedGroups;
            ViewBag.Groups         = db.Product_Groups.ToList();
            ViewBag.Tags           = tags;
            return(View(products));
        }
Ejemplo n.º 17
0
        public ActionResult Create([Bind(Include = "ProductId,Title,Description,Text,Visit,Price,ImageName,Sort")] Product product,
                                   List <int> selectedCategory, HttpPostedFileBase imageProduct, string tags)
        {
            if (ModelState.IsValid)
            {
                // Check Categories
                if (selectedCategory == null)
                {
                    ViewBag.Category   = true;
                    ViewBag.Categories = _categoryBusiness.Get();
                    return(View(product));
                }
                // Image
                product.ImageName = "user123456789.png";
                if (imageProduct != null && imageProduct.IsImage())
                {
                    product.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imageProduct.FileName);
                    imageProduct.SaveAs(Server.MapPath("/Content/Image/Product/" + product.ImageName));
                    ImageResizer img = new ImageResizer();
                    img.Resize(Server.MapPath("/Content/Image/Product/" + product.ImageName),
                               Server.MapPath("/Content/Image/Product/Thumbnail/" + product.ImageName));
                }

                _productBusiness.Insert(product);
                _productBusiness.Save();

                // Category
                foreach (var category in selectedCategory)
                {
                    _productCategoryBusiness.Insert(new ProductCategory()
                    {
                        CategoryId = category,
                        ProductId  = product.ProductId
                    });
                }

                // Tags
                if (!string.IsNullOrEmpty(tags))
                {
                    string[] tagsList = tags.Split(',');
                    foreach (var tag in tagsList)
                    {
                        _tagBusiness.Insert(new Tag()
                        {
                            ProductId = product.ProductId,
                            TagName   = tag.Trim()
                        });
                    }
                }
                _tagBusiness.Save();
                _productCategoryBusiness.Save();

                return(RedirectToAction("Index"));
            }
            ViewBag.Categories = _categoryBusiness.Get();
            return(View(product));
        }
Ejemplo n.º 18
0
        public ActionResult Create(Product product, List <int> selectedCategory, HttpPostedFileBase productImage, string tags)
        {
            if (ModelState.IsValid)
            {
                if (selectedCategory == null)
                {
                    ViewBag.Errorr   = true;
                    ViewBag.Category = context.CategoryRepository.Get();
                    return(View(product));
                }

                //Insert Category
                foreach (var cate in selectedCategory)
                {
                    context.ProductCategoryRepository.Insert(new ProductCategory()
                    {
                        ProductId  = product.Id,
                        CategoryId = cate
                    });
                }

                //Insert Image
                product.ImageName = "noPhoto.jpg";
                if (productImage != null && productImage.IsImage())
                {
                    product.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(productImage.FileName);
                    productImage.SaveAs(Server.MapPath("~/Content/img/Product/" + product.ImageName));
                    ImageResizer img = new ImageResizer();
                    img.Resize(Server.MapPath("~/Content/img/Product/" + product.ImageName),
                               Server.MapPath("~/Content/img/Product/Thumb/" + product.ImageName));
                }

                //Insert Tag
                if (!string.IsNullOrEmpty(tags))
                {
                    string[] tag = tags.Split(',');
                    foreach (string t in tag)
                    {
                        context.ProductTagRepository.Insert(new ProductTag()
                        {
                            ProductId = product.Id,
                            Tag       = t.Trim()
                        });
                    }
                }

                product.Date = DateTime.Now;
                context.ProductRepository.Insert(product);
                context.Save();
                return(RedirectToAction("Index"));
            }

            ViewBag.Category = context.CategoryRepository.Get();
            return(View(product));
        }
Ejemplo n.º 19
0
        public ActionResult Index()
        {
            try
            {
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file           = Request.Files[0];
                    string             baseFolderPath = Server.MapPath(ConfigHelper.GetSettingAsString("UploadsFolderPath"));
                    string             folderPath     = DateTime.Today.ToString("yyyyMM");
                    string             fileName       = Guid.NewGuid() + Path.GetFileNameWithoutExtension(file.FileName).RemoveSpecialChars() + Path.GetExtension(file.FileName);
                    string             fillFullName   = Path.Combine(baseFolderPath, folderPath, fileName);
                    Directory.CreateDirectory(Path.GetDirectoryName(fillFullName));

                    if (file.IsImage())
                    {
                        Image.FromStream(file.InputStream).SaveImage(Path.Combine(baseFolderPath, folderPath), fileName);
                    }
                    else
                    {
                        file.SaveAs(fillFullName);
                    }

                    RfpAttachment upload = new RfpAttachment
                    {
                        rfa_key       = Guid.NewGuid(),
                        rfa_rfp_key   = null,
                        rfa_rfr_key   = null,
                        rfa_cxr_key   = null,
                        rfa_prd_key   = null,
                        rfa_org_key   = null,
                        rfa_file_name = fileName,
                        rfa_file_path = folderPath,
                        rfa_mime      = file.ContentType,
                        rfa_add_date  = DateTime.Now,
                        rfa_add_user  = string.Empty,
                    };

                    var result = _rfpAttachmentFacade.Add(upload, "");

                    return(Json(new { rfa_key = upload.rfa_key, message = "success", Url = Path.Combine(Utility.GetSetting("UploadsURL"), folderPath, fileName) }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { message = "error" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { message = "error" }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 20
0
        public ActionResult Create([Bind(Include = "ProductID,ProductTitle,ShortDescription,Text,OldPrice,Price,ImageName,CreateDate")] Products products, List <int> SelectedGroup, HttpPostedFileBase productImage, string tags)
        {
            if (ModelState.IsValid)
            {
                if (SelectedGroup == null)
                {
                    ViewBag.ErrorSelectedGroup = true;
                    ViewBag.Groups             = db.Product_Groups.ToList();
                    return(View(products));
                }
                products.CreateDate = DateTime.Now;
                products.ImageName  = "NoPhoto.png";

                if (productImage != null && productImage.IsImage())
                {
                    products.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(productImage.FileName);
                    productImage.SaveAs(Server.MapPath("/Images/ProductImages/" + products.ImageName));
                    ImageResizer img = new ImageResizer();
                    img.Resize(Server.MapPath("/Images/ProductImages/" + products.ImageName),
                               Server.MapPath("/Images/ProductImages/Thumb/" + products.ImageName));
                }

                db.Products.Add(products);

                foreach (int selectedGroup in SelectedGroup)
                {
                    db.Product_Selected_Groups.Add(new Product_Selected_Groups()
                    {
                        ProductID = products.ProductID,
                        GroupID   = selectedGroup
                    });
                }
                if (!string.IsNullOrEmpty(tags))
                {
                    string[] tag = tags.Split(',');
                    foreach (var t in tag)
                    {
                        db.Product_Tags.Add(new Product_Tags()
                        {
                            ProductID = products.ProductID,
                            Tags      = t.Trim()
                        });
                    }
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Groups = db.Product_Groups.ToList();
            return(View(products));
        }
Ejemplo n.º 21
0
        public ActionResult AdvertCreate(Advert model, HttpPostedFileBase image)
        {
            var cats = MongoDbContext.db.GetCollection <Category>("Category").Find(n => true).ToListAsync().GetAwaiter().GetResult();

            ViewBag.CategoryId = new SelectList(cats, "Id", "Name");

            //attempt to add the advert
            if (ModelState.IsValid)
            {
                bool addSucceded;

                try
                {
                    if (image != null && image.IsImage())
                    {
                        image.SaveAs(Server.MapPath("~/Content/Images/") + image.FileName);
                        model.Photo = image.FileName;
                    }
                    else
                    {
                        model.Photo = null;
                    }

                    model.Id = ObjectId.GenerateNewId().ToString();
                    model.PublicationDate = DateTime.Now;
                    model.ViewNumber      = 0;
                    //model.VIP = false;
                    model.UserId = MongoDbContext.getUser(User.Identity.Name).Id.ToString();
                    context.AddAdvert(model);
                    addSucceded = true;
                }
                catch (Exception e)
                {
                    addSucceded = false;
                }
                if (addSucceded)
                {
                    return(RedirectToAction("AdvertCreate", new { Message = ManageMessageId.ChangePasswordSuccess }));
                }
                else
                {
                    ModelState.AddModelError("", "Ошибка добавления объявления");
                }
            }



            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 22
0
        public ActionResult Edit(Advert model, HttpPostedFileBase image)
        {
            var cats = MongoDbContext.db.GetCollection <Category>("Category").Find(n => true).ToListAsync().GetAwaiter().GetResult();
            var old  = MongoDbContext.db.GetCollection <Advert>("Advert").Find(m => m.Id == model.Id).FirstAsync().GetAwaiter().GetResult();

            ViewBag.CategoryId = new SelectList(cats, "Id", "Name", model.CategoryId);

            //attempt to edit the advert
            if (ModelState.IsValid)
            {
                bool editSucceded;
                try
                {
                    if (image != null && image.IsImage())
                    {
                        image.SaveAs(Server.MapPath("~/Content/Images/") + image.FileName);
                        model.Photo = image.FileName;
                    }
                    else
                    {
                        model.Photo = old.Photo;
                    }
                    model.PublicationDate = old.PublicationDate;
                    model.ViewNumber      = old.ViewNumber;
                    model.UserId          = old.UserId;
                    //model.VIP = old.VIP;

                    MongoDbContext.db.GetCollection <Advert>("Advert").ReplaceOneAsync(m => m.Id == model.Id, model).GetAwaiter().GetResult();
                    editSucceded = true;
                }
                catch (Exception e)
                {
                    editSucceded = false;
                }
                if (editSucceded)
                {
                    return(RedirectToAction("Edit", new { Message = ManageMessageId.Success }));
                }
                else
                {
                    ModelState.AddModelError("", "Ошибка добавления объявления");
                }
            }



            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 23
0
        public ActionResult SlidersGallery(Slider_Galleries sliderGallery, HttpPostedFileBase galleryImage)
        {
            if (ModelState.IsValid)
            {
                if (galleryImage != null && galleryImage.IsImage())
                {
                    sliderGallery.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(galleryImage.FileName);
                    galleryImage.SaveAs(Server.MapPath("/Images/Sliders/" + sliderGallery.ImageName));
                    db.Slider_Galleries.Add(sliderGallery);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("SlidersGallery", new { id = sliderGallery.SliderID }));
        }
Ejemplo n.º 24
0
        public ActionResult AddBanner(AdvBanner banner, HttpPostedFileBase bannerFile)
        {
            string userInputError = getModelError(banner);

            if (!string.IsNullOrWhiteSpace(userInputError))
            {
                TempData["Error"] = userInputError;
                ViewBag.Mode      = CrudMode.Add;
                return(View("AddEditBanner", banner));
            }
            if (!bannerFile.IsImage())
            {
                TempData["Error"] = "Невірний формат файлу для банеру";
                ViewBag.Mode      = CrudMode.Add;
                return(View("AddEditBanner", banner));
            }

            using (zcrlDbContext = new ZcrlContext())
            {
                AdvBanner newBanner = new AdvBanner()
                {
                    Name = banner.Name, DestUrl = banner.DestUrl, ViewPriority = banner.ViewPriority
                };
                try
                {
                    string newFileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(bannerFile.FileName);
                    string newFilePath = System.IO.Path.Combine(Server.MapPath(UPLOADFILE_DIR), newFileName);
                    bannerFile.SaveAs(newFilePath);
                    newBanner.ImgName = newFileName;
                    zcrlDbContext.Banners.Add(newBanner);
                    zcrlDbContext.LogJournal.Add(new LogRecord()
                    {
                        СreatedDate = DateTime.Now, RecordType = LogRecordType.BannerAddEdit,
                        Content     = string.Format("Користувач <b>{0} {1}.{2}.</b> створив баннер <b>{3}</b>.", (string)Profile["LastName"], ((string)Profile["FirstName"]).First(), ((string)Profile["MiddleName"]).First(), newBanner.Name)
                    });
                    zcrlDbContext.SaveChanges();
                }
                catch
                {
                    TempData["Error"] = "Помилка при заватаженні файлу, повторіть свою спробу пізніше";
                    ViewBag.Mode      = CrudMode.Edit;
                    return(View("AddEditBanner", banner));
                }

                TempData["SuccessMessage"] = "Баннер успішно додано!";
                return(RedirectToAction("BannersList"));
            }
        }
Ejemplo n.º 25
0
        public ActionResult Create([Bind(Include = "CompanyID,Title,ImageName")] Companies companies, HttpPostedFileBase imgUp)
        {
            if (ModelState.IsValid)
            {
                if (imgUp != null && imgUp.IsImage())
                {
                    companies.ImageName = Guid.NewGuid() + Path.GetExtension(imgUp.FileName);
                    imgUp.SaveAs(Server.MapPath("/Images/CompaniesLogo/" + companies.ImageName));
                }
                db.Companies.Add(companies);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(companies));
        }
Ejemplo n.º 26
0
        public ActionResult Create([Bind(Include = "ProductID,ProductTitle,ShortDescription,Text,Price,ImageName")] Products products, List <int> SelectedGroups, HttpPostedFileBase imageProduct, string tags)
        {
            if (ModelState.IsValid)
            {
                if (SelectedGroups == null)
                {
                    ViewBag.NoSelectedgroup = "true";
                    ViewBag.Groups          = db.ProductGroupRepository.GetAll();
                    return(View(products));
                }
                products.ImageName = "no-image.png";
                if (imageProduct != null && imageProduct.IsImage())
                {
                    products.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imageProduct.FileName);
                    imageProduct.SaveAs(Server.MapPath("/Images/ProductImages/" + products.ImageName));
                    ImageResizer image = new ImageResizer();
                    image.Resize(Server.MapPath("/Images/ProductImages/" + products.ImageName), Server.MapPath("/Images/ProductImages/Thumb/" + products.ImageName));
                }
                products.CreateDate = DateTime.Now;
                db.ProductRepository.Insert(products);
                foreach (int selectedGroup in SelectedGroups)
                {
                    db.SelectedGroupRepository.Insert(new SelectedProductGroup()
                    {
                        ProductID = products.ProductID,
                        GroupID   = selectedGroup
                    });
                }
                if (!string.IsNullOrEmpty(tags))
                {
                    string[] Tags = tags.Split('،');
                    foreach (string tag in Tags)
                    {
                        db.TagsRepository.Insert(new Tags()
                        {
                            ProductID = products.ProductID,
                            Tag       = tag.Trim()
                        });
                    }
                }
                db.Save();

                return(RedirectToAction("Index"));
            }
            ViewBag.Groups = db.ProductGroupRepository.GetAll();
            return(View(products));
        }
Ejemplo n.º 27
0
 public ActionResult Gallery(Product_Galleries galleries, HttpPostedFileBase imgUp)
 {
     if (ModelState.IsValid)
     {
         if (imgUp != null && imgUp.IsImage())
         {
             galleries.ImageName = Guid.NewGuid().ToString() + Path.GetExtension(imgUp.FileName);
             imgUp.SaveAs(Server.MapPath("/Images/ProductImages/" + galleries.ImageName));
             ImageResizer img = new ImageResizer();
             img.Resize(Server.MapPath("/Images/ProductImages/" + galleries.ImageName),
                        Server.MapPath("/Images/ProductImages/Thumb/" + galleries.ImageName));
             db.Product_Galleries.Add(galleries);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Gallery", new { id = galleries.ProductID }));
 }
Ejemplo n.º 28
0
        public async Task <ActionResult> UploadProofOfDelivery(HttpPostedFileBase file, int orderId)
        {
            if (file == null || file.ContentLength == 0)
            {
                ModelState.AddModelError("nofile", @"Seleccione una foto.");
            }
            else
            {
                if (file.ContentLength > 1000000 * 5)
                {
                    ModelState.AddModelError("bigfile", @"La foto elegida es muy grande (max = 5 MB).");
                }
                if (!file.IsImage())
                {
                    ModelState.AddModelError("noimage", @"El archivo seleccionado no es una imagen.");
                }
            }
            var orderModel = await Db.OrderModels.Include(x => x.OrderRequestor).FirstOrDefaultAsync(x => x.Id == orderId);

            if (orderModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Conflict));
            }
            if (!orderModel.CanView(User))
            {
                return(RedirectToAction("RedirectUser", "Account"));
            }
            if (!ModelState.IsValid)
            {
                return(View("Details", orderModel));
            }


            var fileName = Guid.NewGuid().ToString("N") + ".jpg";
            var fileUrl  = _userFiles.UploadOrderFile(file?.InputStream, fileName);

            orderModel.ProofOfDelivery = fileUrl.AbsoluteUri;
            orderModel.LogMessage(User, "New proof of delivery at: " + fileUrl.AbsoluteUri);
            Db.SaveChanges();

            await _ns.SendProofOfDeliveryNotification(orderModel);

            return(Redirect(Request.UrlReferrer?.PathAndQuery));
        }
Ejemplo n.º 29
0
        public ActionResult Create([Bind(Include = "ProductID,ProductGroupID,ProductSubGroupID,ProductTitle,ProductShortText,ProductText,ProductImage,ProductIsFavourite,ProductDateCreate")] Product product, HttpPostedFileBase imgProduct)
        {
            if (ModelState.IsValid)
            {
                product.ProductImage      = "";
                product.ProductDateCreate = DateTime.Now;
                if (imgProduct != null && imgProduct.IsImage())
                {
                    string mainImagePath  = "/Images/ProductImages/MainImage/";
                    string thumbImagePath = "/Images/ProductImages/ThumbImage/";

                    if (!Directory.Exists(thumbImagePath))
                    {
                        Directory.CreateDirectory(Server.MapPath(thumbImagePath));
                    }

                    if (!Directory.Exists(mainImagePath))
                    {
                        Directory.CreateDirectory(Server.MapPath(mainImagePath));
                    }

                    string imageName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(imgProduct.FileName);
                    product.ProductImage = imageName;
                    imgProduct.SaveAs(Server.MapPath(mainImagePath + imageName));

                    ImageResizer img = new ImageResizer();
                    img.Resize(Server.MapPath(mainImagePath + imageName),
                               Server.MapPath(thumbImagePath + imageName));

                    db.Products.Add(product);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("ProductImage", "تصویر را انتخاب کنید!");
                    return(View(product));
                }
            }

            ViewBag.ProductGroupID    = new SelectList(db.ProductGroups, "ProductGroupID", "ProductGroupTitle", product.ProductGroupID);
            ViewBag.ProductSubGroupID = new SelectList(db.ProductGroups, "ProductGroupID", "ProductGroupTitle", product.ProductSubGroupID);
            return(View(product));
        }
Ejemplo n.º 30
0
        //[Route("ProductGalleries/Index/{id}")]
        public ActionResult Create([Bind(Include = "ProductGalleryID,ProductID,ProductColor,ProductImageName,ProductImageTitle")] ProductGallery productGallery, int id, HttpPostedFileBase imgProductGallery)
        {
            productGallery.ProductID = id;
            if (ModelState.IsValid)
            {
                if (imgProductGallery != null && imgProductGallery.IsImage())
                {
                    string mainImagePath  = "/Images/ProductGallery/MainImage/";
                    string thumbImagePath = "/Images/ProductGallery/ThumbImage/";

                    if (!Directory.Exists(thumbImagePath))
                    {
                        Directory.CreateDirectory(Server.MapPath(thumbImagePath));
                    }

                    if (!Directory.Exists(mainImagePath))
                    {
                        Directory.CreateDirectory(Server.MapPath(mainImagePath));
                    }

                    string imageName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(imgProductGallery.FileName);
                    productGallery.ProductImageName = imageName;
                    imgProductGallery.SaveAs(Server.MapPath(mainImagePath + imageName));

                    ImageResizer img = new ImageResizer();
                    img.Resize(Server.MapPath(mainImagePath + imageName),
                               Server.MapPath(thumbImagePath + imageName));

                    db.ProductGalleries.Add(productGallery);
                    db.SaveChanges();
                    return(RedirectToAction("Create"));
                    //return RedirectToAction("Index");
                }
                else
                {
                    ModelState.AddModelError("ProductImageName", "تصویر را انتخاب کنید!");
                    return(View(productGallery));
                }
            }

            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductTitle", productGallery.ProductID);
            return(View(productGallery));
        }