public ActionResult CreateAndEdit(SelectTourViewModel obj)
        {
            try
            {
                Validate(obj);
                if (ModelState.IsValid)
                {
                    Mapper.CreateMap<SelectTourViewModel, SelectTour>();
                    var objSave = Mapper.Map<SelectTour>(obj);
                    objSave.TitleUrl = new BaseController().RewriteTitle(objSave.TourName);
                    db.SelectTours.Add(objSave);

                    if (obj.SelectTourId > 0)
                    {
                        db.Entry(objSave).State = EntityState.Modified;
                    }

                    db.SaveChanges();
                    return RedirectToAction("AllSelectTour");
                }
                obj.LstTourStyle = db.ReferenceValues.Where(o => o.ReferenceId == ReferenceId.TourStyle).ToList();
                return View("CreateNew", obj);
            }
            catch (Exception ex)
            {
                obj.Message = ex.ToString();
                return View("CreateNew", obj);
            }
        }
 public ActionResult CreateNew()
 {
     var objView = new SelectTourViewModel()
     {
         LstTourStyle = db.ReferenceValues.Where(o => o.ReferenceId == ReferenceId.TourStyle).ToList(),
         LstAreas = db.ReferenceValues.Where(o => o.ReferenceId == ReferenceId.Areas).ToList()
     };
     return View(objView);
 }
 private void Validate(SelectTourViewModel obj)
 {
     ModelState.Clear();
     if (string.IsNullOrEmpty(obj.TourRoute))
         ModelState.AddModelError("TourName", "Tour Name is required !");
 }
        public ActionResult Edit(int id)
        {
            try
            {
                var objSelectTour = db.SelectTours.First(o => o.SelectTourId == id);
                var objSelectTourViewModel = new SelectTourViewModel()
                {
                    SelectTourId = objSelectTour.SelectTourId,
                    TourName = objSelectTour.TourName,
                    Detail = objSelectTour.Detail,
                    AgencyStandard2 = objSelectTour.AgencyStandard2,
                    AgencyStandard35 = objSelectTour.AgencyStandard35,
                    AgencyStandard69 = objSelectTour.AgencyStandard69,
                    AgencySuperior2 = objSelectTour.AgencySuperior2,
                    AgencySuperior35 = objSelectTour.AgencySuperior35,
                    AgencySuperior69 = objSelectTour.AgencySuperior69,
                    Agency2Standard2 = objSelectTour.Agency2Standard2,
                    Agency2Standard35 = objSelectTour.Agency2Standard35,
                    Agency2Standard69 = objSelectTour.Agency2Standard69,
                    Agency2Superior2 = objSelectTour.Agency2Superior2,
                    Agency2Superior35 = objSelectTour.Agency2Superior35,
                    Agency2Superior69 = objSelectTour.Agency2Superior69,
                    GuestStandard2 = objSelectTour.GuestStandard2,
                    GuestStandard35 = objSelectTour.GuestStandard35,
                    GuestStandard69 = objSelectTour.GuestStandard69,
                    GuestSuperior2 = objSelectTour.GuestSuperior2,
                    GuestSuperior35 = objSelectTour.GuestSuperior35,
                    GuestSuperior69 = objSelectTour.GuestSuperior69,
                    Remove = objSelectTour.Remove,
                    Special = objSelectTour.Special,
                    Style = objSelectTour.Style,
                    Duration = objSelectTour.Duration,
                    TourRoute = objSelectTour.TourRoute,
                    AgencyDeluxe2 = objSelectTour.AgencyDeluxe2,
                    AgencyDeluxe35 = objSelectTour.AgencyDeluxe35,
                    AgencyDeluxe69 = objSelectTour.AgencyDeluxe69,
                    Agency2Deluxe2 = objSelectTour.Agency2Deluxe2,
                    Agency2Deluxe35 = objSelectTour.Agency2Deluxe35,
                    Agency2Deluxe69 = objSelectTour.Agency2Deluxe69,
                    GuestDeluxe2 = objSelectTour.GuestDeluxe2,
                    GuestDeluxe35 = objSelectTour.GuestDeluxe35,
                    GuestDeluxe69 = objSelectTour.GuestDeluxe69,
                    Agency1SingleSupplementStandard = objSelectTour.Agency1SingleSupplementStandard,
                    Agency1SingleSupplementSuperior = objSelectTour.Agency1SingleSupplementSuperior,
                    Agency1SingleSupplementDeluxe = objSelectTour.Agency1SingleSupplementDeluxe,
                    Agency2SingleSupplementStandard = objSelectTour.Agency2SingleSupplementStandard,
                    Agency2SingleSupplementSuperior = objSelectTour.Agency2SingleSupplementSuperior,
                    Agency2SingleSupplementDeluxe = objSelectTour.Agency2SingleSupplementDeluxe,
                    GuestSingleSupplementStandard = objSelectTour.GuestSingleSupplementStandard,
                    GuestSingleSupplementSuperior = objSelectTour.GuestSingleSupplementSuperior,
                    GuestSingleSupplementDeluxe = objSelectTour.GuestSingleSupplementDeluxe,
                    Image = objSelectTour.Image,
                    Areas = objSelectTour.Areas,
                    Sort = objSelectTour.Sort,
                    LstTourStyle = db.ReferenceValues.Where(o => o.ReferenceId == ReferenceId.TourStyle).ToList(),
                    LstAreas = db.ReferenceValues.Where(o => o.ReferenceId == ReferenceId.Areas).ToList(),
                };
                return View("CreateNew", objSelectTourViewModel);

            }
            catch (Exception ex)
            {

                throw new System.ArgumentException(ex.Message);
            }
        }