Exemplo n.º 1
0
        public ActionResult Edit(TourCreateEditModel tour, int Id)
        {
            Tour          thisTour   = db.Tours.Find(Id);
            List <string> Categories = new List <string>();

            foreach (int catId in tour.Categories)
            {
                Categories.Add(db.Categories.Find(catId).CategoryName.ToLower());
            }

            if (ModelState.IsValid)
            {
                thisTour.FromId              = tour.FromCity;
                thisTour.DestinationId       = tour.DestCity;
                thisTour.Price               = (decimal)tour.Price;
                thisTour.CurrencyId          = tour.Currency;
                thisTour.Duration            = tour.Duration;
                thisTour.DurationTypeId      = tour.DurationType;
                thisTour.Category            = String.Join(",", Categories.ToArray());
                thisTour.AccomodationId      = tour.Accomodation != null ? tour.Accomodation : null;
                thisTour.AccomodationLevelId = tour.AccomodationLvl != null ? tour.AccomodationLvl : null;
                thisTour.Vehicle             = tour.Transport;
                thisTour.Description         = tour.Description;
                thisTour.Approved            = 0;

                db.Entry(thisTour).State = EntityState.Modified;
                db.SaveChanges();
            }

            if (tour.Images.Count > 0)
            {
                foreach (HttpPostedFileBase img in tour.Images)
                {
                    string fileName = tour.GuideId + DateTime.Now.ToString("yyyyMMddHHmmss") + img.FileName;
                    string path     = System.IO.Path.Combine(Server.MapPath("~/uploads"), fileName);
                    img.SaveAs(path);
                    string    image     = "/uploads/" + fileName;
                    TourImage tourImage = new TourImage
                    {
                        ImageURL = image,
                        TourId   = thisTour.Id,
                    };
                    db.TourImages.Add(tourImage);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("edit", new { thisTour.Id }));
        }
Exemplo n.º 2
0
        public ActionResult Create(TourCreateEditModel tour)
        {
            if (ModelState.IsValid)
            {
                List <string> Categories = new List <string>();
                foreach (int catId in tour.Categories)
                {
                    Categories.Add(db.Categories.Find(catId).CategoryName.ToLower());
                }

                Tour newTour = new Tour
                {
                    GuideId             = tour.GuideId,
                    FromId              = tour.FromCity,
                    DestinationId       = tour.DestCity,
                    Price               = (decimal)tour.Price,
                    CurrencyId          = tour.Currency,
                    Category            = String.Join(",", Categories.ToArray()),
                    Duration            = tour.Duration,
                    DurationTypeId      = tour.DurationType,
                    AccomodationId      = tour.Accomodation != null ? tour.Accomodation : null,
                    AccomodationLevelId = tour.AccomodationLvl != null ? tour.AccomodationLvl : null,
                    Vehicle             = tour.Transport,
                    Description         = tour.Description,
                    PostedDate          = DateTime.Now,
                    MainImageId         = 1,
                    Status              = 0,
                    Approved            = 0
                };
                db.Tours.Add(newTour);
                db.SaveChanges();

                if (tour.Images.Count > 0)
                {
                    foreach (HttpPostedFileBase img in tour.Images)
                    {
                        string fileName = tour.GuideId + DateTime.Now.ToString("yyyyMMddHHmmss") + img.FileName;
                        string path     = System.IO.Path.Combine(Server.MapPath("~/uploads"), fileName);
                        img.SaveAs(path);
                        string    image     = "/uploads/" + fileName;
                        TourImage tourImage = new TourImage
                        {
                            ImageURL = image,
                            TourId   = newTour.Id,
                        };
                        db.TourImages.Add(tourImage);
                        db.SaveChanges();
                    }
                }

                newTour.MainImageId = db.TourImages.Where(ti => ti.TourId == newTour.Id).OrderBy(ti => ti.Id).FirstOrDefault().Id;
                db.SaveChanges();

                Notification noti = new Notification
                {
                    UserId             = db.Users.FirstOrDefault(u => u.AccountType == 2).Id,
                    Text               = "New tour from " + db.Users.Find(tour.GuideId).Fullname,
                    Date               = DateTime.Now,
                    NotificationTypeId = 8,
                    Link               = "0",
                    Status             = 0,
                };
                db.Notifications.Add(noti);
                db.SaveChanges();
                noti.Link = "/admin/tours/details/?id=" + newTour.Id + "&notiId=" + noti.Id;
                db.SaveChanges();
            }
            ;

            return(RedirectToAction("index", new { controller = "tours", area = "manage", id = tour.GuideId }));
        }