public ActionResult Edit(TouristPlace touristPlace, HttpPostedFileBase imagePath)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (imagePath != null)
                    {
                        var    extensionOfImage = Path.GetFileName(imagePath.FileName).Split('.');
                        var    fileNameOriginal = Guid.NewGuid().ToString() + "." + extensionOfImage[1];
                        var    filePathOriginal = Request.MapPath(Request.ApplicationPath) + @"/Content/Place_Images";
                        string savedOrgFileName = Path.Combine(filePathOriginal, fileNameOriginal);

                        touristPlace.ImagePath = "/Content/Place_Images/" + fileNameOriginal;

                        if (_touristPlacesService.UpdateTouristPlace(touristPlace))
                        {
                            imagePath.SaveAs(savedOrgFileName);
                        }

                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
            }
            return(View(touristPlace));
        }
Пример #2
0
        public List <TouristPlace> GetTouristPlaces(int subCategoryID, int cityID)
        {
            String sql = "SELECT * FROM Tourist_Place where SubCategoryID=@1 AND CityID=@2";
            List <TouristPlace> touristPlaceList = new List <TouristPlace>();

            using (MySqlConnection conn = new MySqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["RajasthanTourismDB_ConnectionString"].ConnectionString;
                conn.Open();
                using (MySqlCommand command = new MySqlCommand(sql, conn))
                {
                    command.Parameters.AddWithValue("@1", subCategoryID);
                    command.Parameters.AddWithValue("@2", cityID);

                    MySqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        TouristPlace touristPlace = new TouristPlace();
                        touristPlace.place       = reader["Place"].ToString();
                        touristPlace.imageUrl    = reader["ImageUrl"].ToString();
                        touristPlace.description = reader["Description"].ToString();
                        touristPlace.hyperlink   = reader["Hyperlink"].ToString();
                        touristPlaceList.Add(touristPlace);
                    }
                    reader.Close();
                }
            }
            return(touristPlaceList);
        }
 public async Task <IActionResult> Create(TouristPlace touristPlace)
 {
     try
     {
         touristPlaceManager.Add(touristPlace);
         return(Ok(touristPlace));
     }
     catch (Exception)
     {
         throw;
     }
 }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TouristPlace touristPlace = _touristPlacesService.GetTouristPlaceDetailsById(id.Value);

            if (touristPlace == null)
            {
                return(HttpNotFound());
            }
            return(View(touristPlace));
        }
 public bool UpdateTouristPlace(TouristPlace touristPlace)
 {
     try
     {
         _touristPlacesRepository.Update(touristPlace);
         SaveRecord();
         return(true);
     }
     catch (Exception ex)
     {
         ex.Message.ToString();
         return(false);
     }
 }
Пример #6
0
        public bool InsertTPlace(TouristPlace obj)
        {
            bool status = false;

            using (dbcon = new TourismWebsiteDBEntities())
            {
                dbcon.TouristPlaces.Add(obj);
                int changes = dbcon.SaveChanges();
                if (changes > 0)
                {
                    status = true;
                }
            }

            return(status);
        }
Пример #7
0
        public bool UpdatePlace(TouristPlace obj)
        {
            bool status = false;

            using (dbcon = new TourismWebsiteDBEntities())
            {
                var uobj = dbcon.TouristPlaces.Where(x => x.Id == obj.Id).First();
                uobj.PlaceName = obj.PlaceName;
                uobj.Ratings   = obj.Ratings;

                int changes = dbcon.SaveChanges();
                if (changes > 0)
                {
                    status = true;
                }
            }
            return(status);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            TouristPlace touristPlace = _touristPlacesService.GetTouristPlaceDetailsById(id);

            try
            {
                if (_touristPlacesService.DeleteTouristPlace(touristPlace))
                {
                    ViewBag.Message = "Successfully deleted";
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                ViewBag.Message = "Operation failed";
            }

            return(RedirectToAction("Index"));
        }
 public IActionResult Create([Bind("Name,Address,TypeId,Rating,ImageFile")] TouristPlaceViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.ImageFile != null)
         {
             string wwwRootPath = _hostEnvironment.WebRootPath;
             string fileName    = Path.GetFileNameWithoutExtension(model.ImageFile.FileName);
             string extension   = Path.GetExtension(model.ImageFile.FileName);
             model.Image = fileName = fileName + Guid.NewGuid() + extension;
             string path = Path.Combine(wwwRootPath + "/image/", fileName);
             using var fileStream = new FileStream(path, FileMode.Create);
             model.ImageFile.CopyTo(fileStream);
         }
         TouristPlace entity = _mapper.Map <TouristPlace>(model);
         touristPlaceService.InsertTouristPlace(entity);
         if (entity.Id > 0)
         {
             return(Redirect(GetRedirectUrl()));
         }
     }
     ViewBag.Types = new SelectList(touristPlaceTypeService.GetTouristPlaceTypes(), "Id", "TypeName");
     return(View(model));
 }
 public void DeleteTouristPlace(TouristPlace entity)
 {
     touristPlaceRepository.Delete(entity);
 }
 public void UpdateTouristPlace(TouristPlace entity)
 {
     touristPlaceRepository.Update(entity);
 }
 public void InsertTouristPlace(TouristPlace entity)
 {
     touristPlaceRepository.Insert(entity);
 }