Example #1
0
        void ReleaseDesignerOutlets()
        {
            if (OfferBody != null)
            {
                OfferBody.Dispose();
                OfferBody = null;
            }

            if (OfferHeadline != null)
            {
                OfferHeadline.Dispose();
                OfferHeadline = null;
            }

            if (OfferImage != null)
            {
                OfferImage.Dispose();
                OfferImage = null;
            }

            if (offerValidDate != null)
            {
                offerValidDate.Dispose();
                offerValidDate = null;
            }

            if (OfferValue != null)
            {
                OfferValue.Dispose();
                OfferValue = null;
            }
        }
        public ActionResult AddOffer(Offer offer, HttpPostedFileBase images)
        {
            try
            {
                int shopId = int.Parse(Session["id"].ToString());     //shop Id
                int result = DateTime.Compare(offer.StartDate, offer.EndDate);

                if (result > 0)
                {
                    Response.Write("<script>alert('Start Date couldnt be later than End date.');</script>");
                    return(View(offer));
                }

                if (images != null)
                {
                    offer.ShopID = shopId;
                    db.Offers.Add(offer);
                    db.SaveChanges();

                    int offerId = offer.ID;              //Offer Id


                    OfferImage photo = new OfferImage();

                    photo.Image = new byte[images.ContentLength];
                    images.InputStream.Read(photo.Image, 0, images.ContentLength);

                    photo.OfferID = offerId;

                    db.OfferImages.Add(photo);
                    db.SaveChanges();



                    return(RedirectToAction("ListAllOffers"));
                }

                else
                {
                    //Check image is submitted or not

                    Response.Write("<script>alert('Select Photo Please.');</script>");
                }

                return(View(offer));
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('Exception');</script>");
                Response.Write("<script>alert('" + ex.Message + "');</script>");

                return(View(offer));
            }
        }
Example #3
0
        public static IHtmlString ImgArticleHelper(OfferImage images, string alt, bool flag)
        {
            var    img    = (images == null) ? "http://placehold.it/590x590" : images.PathOnDisk;
            string active = null;

            if (flag)
            {
                active = "active";
            }
            string html = String.Format("<div class='item {0}'><a href='#'><img src='{1}' data-echo='{2}' alt='{3}' class='img-responsive img-caroussel' /></a></div>", active, img, img, alt);

            return(new HtmlString(html));
        }
Example #4
0
        public JsonResult AddImage(HttpPostedFileBase image)
        {
            var uploadsPath = Server.MapPath(UPLOADS_PATH);
            var offerImage  = new OfferImage();

            offerImage.SaveImageTemporarily(image, User.Identity.GetUserId(), uploadsPath);

            if (Session["images"] == null)
            {
                Session["images"] = new List <OfferImage>();
            }

            //offerImage.Id = Guid.NewGuid();
            (Session["images"] as List <OfferImage>).Add(offerImage);
            return(Json(new { thumbPath = offerImage.RelativeThumbnailPath }, contentType: "application/json"));
        }
        public ActionResult EditOffer(Offer offer, HttpPostedFileBase images)
        {
            try
            {
                int result = DateTime.Compare(offer.StartDate, offer.EndDate);

                if (result > 0)
                {
                    Response.Write("<script>alert('Start Date couldnt be later than End date.');</script>");
                    return(View(offer));
                }

                //Update the offer
                db.Entry(offer).State = EntityState.Modified;
                db.SaveChanges();

                //update the images of the offer
                if (images != null)
                {
                    int offerId = offer.ID;          //Offer Id

                    //Delete old Images
                    db.OfferImages.RemoveRange(db.OfferImages.Where(i => i.OfferID == offerId));


                    OfferImage photo = new OfferImage();

                    photo.Image = new byte[images.ContentLength];
                    images.InputStream.Read(photo.Image, 0, images.ContentLength);

                    photo.OfferID = offerId;

                    db.OfferImages.Add(photo);
                    db.SaveChanges();
                }    // End IF


                return(RedirectToAction("ListAllOffers"));
            }
            catch
            {
                ViewBag.StartDate = offer.StartDate.ToString("yyyy-MM-ddTHH:mmK");
                ViewBag.EndDate   = offer.EndDate.ToString("yyyy-MM-ddTHH:mmK");
                return(View(offer));
            }
        }
        protected OfferImage GetOfferImage(MemoryStream target, int offerId, string offerType)
        {
            var offerImage = new OfferImage()
            {
                Image = target.ToArray(),
            };

            if (offerType == "CarOffer")
            {
                offerImage.CarOfferId = offerId;
            }
            else if (offerType == "MotorcycleOffer")
            {
                offerImage.MotorcycleOfferId = offerId;
            }
            else if (offerType == "ElectricScooterOffer")
            {
                offerImage.ElectricScooterOfferId = offerId;
            }

            return(offerImage);
        }
Example #7
0
 public static string ThbImgArticleHelper(OfferImage images)
 {
     return((images == null) ? "http://placehold.it/262x202" : images.ThumbnailPathOnDisk);
 }
        public async Task CreateAsync(AddOfferInputModel input, string imagePath)
        {
            var offer = new Offer
            {
                ValidTo        = (DateTime)input.ValidTo,
                ValidFrom      = (DateTime)input.ValidFrom,
                PropertyId     = input.PropertyId,
                PricePerPerson = input.PricePerPerson,
                Count          = input.Count,
            };

            var index       = 0;
            var count       = 0;
            var bedTypesIds = this.bedTypesRepository
                              .All()
                              .OrderBy(b => b.Type)
                              .Select(b => b.Id)
                              .ToList();
            var bedTypesDb = this.bedTypesRepository
                             .All()
                             .Select(b => new
            {
                b.Id,
                b.Capacity,
            })
                             .ToList();

            foreach (var bedTypeId in bedTypesIds)
            {
                var id           = bedTypeId;
                var bedTypeCount = input.BedTypesCounts.ToList()[index];
                if (bedTypeCount > 0)
                {
                    for (int i = 0; i < bedTypeCount; i++)
                    {
                        var offerBedType = new OfferBedType
                        {
                            BedTypeId = id,
                            Offer     = offer,
                        };
                        offer.OfferBedTypes.Add(offerBedType);
                    }

                    count += bedTypesDb.First(x => x.Id == bedTypeId).Capacity *bedTypeCount;
                    if (count > 30)
                    {
                        throw new Exception(GlobalConstants.ErrorMessages.MembersCount);
                    }
                }

                index++;
            }

            if (count <= 0)
            {
                throw new Exception(GlobalConstants.ErrorMessages.MembersCount);
            }

            var facilitiesIds = input.OfferFacilitiesIds;

            if (facilitiesIds != null)
            {
                foreach (var facilityId in facilitiesIds)
                {
                    var offerFacility = new OfferFacility
                    {
                        Offer      = offer,
                        FacilityId = facilityId,
                    };

                    offer.OfferFacilities.Add(offerFacility);
                }
            }

            Directory.CreateDirectory(imagePath);
            if (input.Images != null && input.Images.Any())
            {
                foreach (var image in input.Images)
                {
                    var extension = Path.GetExtension(image.FileName).TrimStart('.');
                    if (!this.allowedExtensions.Any(x => extension.EndsWith(x)))
                    {
                        throw new Exception($"{GlobalConstants.ErrorMessages.ImageExtention} {extension}");
                    }

                    var offerImage = new OfferImage
                    {
                        Extension = extension,
                    };
                    offer.OfferImages.Add(offerImage);

                    var physicalPath = $"{imagePath}{offerImage.Id}.{extension}";
                    using Stream fileStream = new FileStream(physicalPath, FileMode.Create);
                    await image.CopyToAsync(fileStream);
                }
            }

            await this.offersRepository.AddAsync(offer);

            await this.offersRepository.SaveChangesAsync();
        }