Ejemplo n.º 1
0
        public UserAdImageVM GetUserAdImageByAdImageId(int imageId)
        {
            var userAdImage = _userAdRepository.GetUserAdImageByAdImageId(imageId);

            var userAdImageVM = new UserAdImageVM();

            Mapper.Map(userAdImage, userAdImageVM);
            return(userAdImageVM);
        }
Ejemplo n.º 2
0
        public long AddUserAdImage(UserAdImageVM userAdImageVM)
        {
            var imageId = _userAdRepository.AddUserAdImage(new UserAdImage
            {
                AdID            = userAdImageVM.AdID,
                AdImageOriginal = userAdImageVM.AdImageOriginal,
                AdImageSelected = userAdImageVM.AdImageSelected,
                ImageNumber     = userAdImageVM.ImageNumber,
                CreatedOn       = userAdImageVM.CreatedOn
            });

            return(imageId);
        }
Ejemplo n.º 3
0
        public ActionResult AdWizardStep1(int?adID)
        {
            _dbContext = new ApplicationDbContext();
            var           userAdService = new UserAdService(_dbContext);
            UserAdImageVM adImageVM     = new UserAdImageVM();

            if (TempData["ImageUploadedId"] != null)
            {
                adImageVM = userAdService.GetUserAdImageByAdImageId(Convert.ToInt32(TempData["ImageUploadedId"]));
            }

            // get user ad images
            if (adID != null)
            {
                ViewBag.AdId                = adID;
                ViewBag.AdImages            = userAdService.GetUserAdImages((int)adID);
                ViewBag.TotalImagesUploaded = userAdService.GetUserAdImages((int)adID).Count;
                ViewBag.ImageNumber         = ViewBag.TotalImagesUploaded + 1;
            }
            else
            {
                // if first image is not uploaded then set AdId = 0
                ViewBag.AdId                = 0;
                ViewBag.AdImages            = null;
                ViewBag.TotalImagesUploaded = 0;
                ViewBag.ImageNumber         = 1;
            }

            if (adImageVM == null)
            {
                return(HttpNotFound());
            }

            if (TempData["ImageUploaded"] != null)
            {
                ViewBag.OpenEditProfileImageModel = true;
            }

            ViewBag.OpenEditProfileImageModel = false;

            // check if first image is uploaded or not
            if (adID != null)
            {
                // open the cropping tool based on image upload success
                ViewBag.OpenEditProfileImageModel = true;
            }

            return(View(adImageVM));
        }
Ejemplo n.º 4
0
        public ActionResult UploadAdImage(HttpPostedFileBase adImage, string returnUrl, int adImageNumber, int adID, string SubmitAction = "")
        {
            string newAdImageFilename = "";

            //int adID = 0;
            if (adImage != null)
            {
                if (adImage.ContentLength > 0)
                {
                    _dbContext = new ApplicationDbContext();
                    var userAdService = new UserAdService(_dbContext);

                    //Save an Ad first and get newly created Ad's ID
                    if (adID == 0)
                    {
                        var userAdVM = new UserAdVM
                        {
                            UserId    = User.Identity.GetUserId(),
                            CreatedOn = DateTime.UtcNow,
                            IsDraft   = true
                        };
                        adID = userAdService.CreateAd(userAdVM);
                    }

                    // UnComment After making it dynamic
                    var userAdImage = userAdService.GetUserAdImages(adID).Where(w => w.ImageNumber == adImageNumber).FirstOrDefault();

                    //Save New Ad Image and Remove Old Image
                    string adImageName = DateTime.UtcNow.ToString("yyyyddmmhhmmss") + "_ad_original.jpg";
                    string adImagePath = Server.MapPath("~" + _FileSavingPaths.UserAdsPath + "/" + adImageName);

                    //Save New Image
                    if (!System.IO.File.Exists(adImagePath))
                    {
                        adImage.SaveAs(adImagePath);
                    }

                    //Remove Old Image
                    // UnComment After making it dynamic
                    if (userAdImage != null)
                    {
                        try
                        {
                            //Delete Original and Selected Images

                            if (System.IO.File.Exists(Server.MapPath("~" + _FileSavingPaths.UserAdsPath + "/" + userAdImage.AdImageOriginal)))
                            {
                                System.IO.File.Delete(Server.MapPath("~" + _FileSavingPaths.UserAdsPath + "/" + userAdImage.AdImageOriginal));
                            }
                            if (System.IO.File.Exists(Server.MapPath("~" + _FileSavingPaths.UserAdsPath + "/" + userAdImage.AdImageSelected)))
                            {
                                System.IO.File.Delete(Server.MapPath("~" + _FileSavingPaths.UserAdsPath + "/" + userAdImage.AdImageSelected));
                            }
                        }
                        catch { }
                    }

                    //Add user Ad image in database
                    var userAdImageVM = new UserAdImageVM
                    {
                        AdImageOriginal = adImageName,
                        AdImageSelected = adImageName,
                        ImageNumber     = adImageNumber,
                        CreatedOn       = DateTime.UtcNow,
                        AdID            = adID
                    };
                    var uploadedImageId = userAdService.AddUserAdImage(userAdImageVM);

                    newAdImageFilename = adImageName;

                    //// Increment the image number after saving the previous image
                    //ViewBag.

                    //userProfile.ProfileImageOriginal = profileImageName;
                    //userProfile.ProfileImageSelected = profileImageName;
                    //newProfileImageFilename = profileImageName;
                    //userAccountService.UpdateUserProfileImage(userProfile, false);

                    //Set the Image Uploaded
                    TempData["ImageUploaded"]   = true;
                    TempData["ImageUploadedId"] = uploadedImageId;
                    TempData["ResponseResult"]  = new ResponseResult <object>
                    {
                        Success     = true,
                        Message     = "Ad Image is uploaded successfully.",
                        MessageCode = ResponseResultMessageCode.ProfileImageUploaded,
                    };
                }
            }

            if (SubmitAction.ToLower().Equals(Strings.Next.ToLower()) && adID != 0)
            {
                // store the adId in tempData
                //TempData["AdId"] = adID;
                return(RedirectToAction("AdWizardStep2", "Ad", new { adID }));
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new ResponseResult <string>
                {
                    Success = true,
                    Data = newAdImageFilename
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                if (!string.IsNullOrEmpty(returnUrl))
                {
                    if (adImage == null)
                    {
                        TempData["ResponseResult"] = new ResponseResult <object>
                        {
                            Success     = false,
                            Message     = "Please upload atleast one image to continue to the next step.",
                            MessageCode = ResponseResultMessageCode.ProfileImageUploaded,
                        };

                        return(Redirect(returnUrl));
                    }

                    return(RedirectToAction("AdWizardStep1", "Ad", new { adID }));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
        }