Esempio n. 1
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));
        }
Esempio n. 2
0
        public ActionResult AdWizardStep4(int adID)
        {
            try
            {
                _dbContext = new ApplicationDbContext();

                // get user Id
                string currentUserId = User.Identity.GetUserId();
                // define service
                UserAccountService   userAccountService   = new UserAccountService(_dbContext);
                UserAdService        userAdService        = new UserAdService(_dbContext);
                ConfigurationService configurationService = new ConfigurationService(_dbContext);
                CurrencyService      currencyService      = new CurrencyService(_dbContext);

                // Get The User
                ViewBag.User = userAccountService.GetUserProfileById(currentUserId);
                // Get the ad info
                ViewBag.AdInfo        = userAdService.GetUserAdInfoByAdId(adID);
                ViewBag.AdInfoImages  = userAdService.GetUserAdImages(adID)[0];
                ViewBag.AdPriceReward = userAdService.GetUserAdPriceRewardByAdId(adID);
                // get user preferred currency
                var currencyUser = userAccountService.GetUserProfileById(currentUserId).PreferredCurrency;
                // get currency symbol by user currency
                ViewBag.Currency = currencyService.GetCurrencyByCurrencyCode(currencyUser).Symbol;

                ViewBag.AdId = adID;
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.InnerException + ex.Message;
                return(View("Error"));
            }
        }
Esempio n. 3
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"));
                }
            }
        }