public IHttpActionResult PostTourDetails(TourDetails tourDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var list = db.TourDetailses.Where(x => x.TourId == tourDetails.TourId && x.DateStart == tourDetails.DateStart &&
                                              x.DateFinish == tourDetails.DateFinish).ToList();

            if (list.Count != 0)
            {
                tourDetails.CurrentCountOfBusinessPassenger +=
                    list.OrderBy(x => x.CurrentCountOfBusinessPassenger).First().CurrentCountOfBusinessPassenger;
                tourDetails.CurrentCountOfEconomyPassenger +=
                    list.OrderBy(x => x.CurrentCountOfEconomyPassenger).First().CurrentCountOfEconomyPassenger;
            }

            tourDetails.BookedPlaces = null;
            tourDetails.DatePushed   = DateTime.Now;

            db.TourDetailses.Add(tourDetails);
            db.SaveChanges();


            return(Ok(tourDetails));
        }
        public IHttpActionResult PutTourDetails(int id, TourDetails tourDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tourDetails.TourDetailsId)
            {
                return(BadRequest());
            }

            db.Entry(tourDetails).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TourDetailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult DeleteTourDetails(int id)
        {
            TourDetails tourDetails = db.TourDetailses.Find(id);

            if (tourDetails == null)
            {
                return(NotFound());
            }

            db.TourDetailses.Remove(tourDetails);
            db.SaveChanges();

            return(Ok(tourDetails));
        }
Beispiel #4
0
        public dynamic SaveTourDetails(TourDetails tourDetails, int userSessionId)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter("@TourName",  Convert.ToString(tourDetails.TourName).Trim()),
                new SqlParameter("@Location",  Convert.ToString(tourDetails.Destination).Trim()),
                new SqlParameter("@CountryId", tourDetails.CountryId),
                new SqlParameter("@Days",      tourDetails.Days),
                new SqlParameter("@Nights",    tourDetails.Nights),
                new SqlParameter("@Cost",      tourDetails.Cost),
                new SqlParameter("@CreatedBy", userSessionId)
            };

            return(repository.ExecuteStoredProcedureScalar <TourDetails>("ProcSaveTourDetails", parameters));
        }
        // GET: tbl_Tour/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(RedirectToAction("Error", "Home", new { message = "Trang không tồn tại" }));
            }
            //tbl_Tour tbl_Tour = await db.tbl_Tour.Where(a => a.ID == id).Include(a => a.tbl_Image).SingleOrDefaultAsync();


            var tour = _tourService.getTourByID(id);

            if (tour == null)
            {
                return(RedirectToAction("Error", "Home", new { message = "Trang không tồn tại" }));
            }
            else
            {
                TourDetails viewModel = new TourDetails();
                viewModel.tbl_Tour = tour;

                IOfficeService _officeService = new OfficeService();
                viewModel.tbl_OfficeSouth           = _officeService.getAllOfficeInSouthVietNam();
                viewModel.tbl_OfficeCenter          = _officeService.getAllOfficeInCenterVietNam();
                viewModel.tbl_OfficeNorth           = _officeService.getAllOfficeInNorthVietNam();
                viewModel.tbl_MainOffice            = _officeService.getAllMainOfficeInVietNam();
                viewModel.SamePriceTourList         = _tourService.getNTourByPrice(tour.PriceForAdult, tour.ID, 5);
                viewModel.SameDatedepartureTourList = _tourService.getNTourByDateBegin(tour.TimeBegin, tour.ID, 5);

                viewModel.listComboBoxFromPlace = _tourService.listComboBoxToPlace();
                viewModel.listComboBoxToPlace   = _tourService.listComboBoxFromPlace();

                int days = -tour.TimeEnd.Subtract(tour.TimeBegin).Days;
                viewModel.SameDurationTourList = _tourService.getNTourByDuration(days, tour.ID, 5);


                ViewBag.isActive = UtilContants.PLACE_NAV;
                return(View(viewModel));
            }
        }
        public JsonResult SaveTourDetails(string TourData)
        {
            string fileSavePath = "", tourCode = "";

            try
            {
                // Write Asyn method for Pkg Upload and Save Data
                //int userSessionId = Convert.ToInt32(Session["UserId"]);

                var         serializer  = new System.Web.Script.Serialization.JavaScriptSerializer();
                TourDetails tourDetails = serializer.Deserialize <TourDetails>(TourData);
                var         tourDet     = _TourProcess.SaveTourDetails(tourDetails, 1 /*userSessionId*/);
                tourCode = tourDet.TourCode;
                if (Request.Files.Count > 0)
                {
                    serverPath = serverPath + "/" + tourCode;
                    if (!(Directory.Exists(serverPath)))
                    {
                        Directory.CreateDirectory(Server.MapPath(serverPath));
                    }


                    for (int i = 0; i < Request.Files.Count; i++)
                    {
                        var file = Request.Files[i];
                        fileSavePath = Path.Combine(Server.MapPath(serverPath), file.FileName);
                        file.SaveAs(fileSavePath);
                        _TourProcess.SaveTourImgDetails(tourDet.TourId, file.FileName);
                    }
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }
            return(Json(new { success = true, tourCode }));
        }
 public async Task UpdateTourDetails(TourDetails tourDetails)
 {
     _context.TourDetails.Update(tourDetails);
     await _context.SaveChangesAsync();
 }
        public async Task AddTourDetails(TourDetails tourDetails)
        {
            await _context.TourDetails.AddAsync(tourDetails);

            await _context.SaveChangesAsync();
        }