// GET: Place/Create public ActionResult Create() { PlaceVm vm = new PlaceVm(); vm.PlaceTypes = GetAllPlaceTypes(); return(View(vm)); }
public IActionResult RouteList() { if (HttpContext.Session.GetString("UserRole") != null) { var a = _context.Places.AsNoTracking().ToList(); var s = new List <PlaceVm>(); int c = 1; foreach (var item in a) { PlaceVm p = new PlaceVm() { PlaceName = item.PlaceName, PlaceVmId = item.PlaceId, Serial = c }; s.Add(p); c++; } return(View(s)); } else { return(RedirectToAction("Index", "Home")); } }
public async Task <ActionResult <PlaceModel> > PostPlaceModel([FromForm] PlaceVm placeVModel) { var filePath = ""; try { if (placeVModel.image.Length > 0) { //string path = _webHostEnvironment.WebRootPath + "\\uploads\\"; //if (!Directory.Exists(path)) //{ // Directory.CreateDirectory(path); //} //using (FileStream fileStream = System.IO.File.Create(path + placeVModel.image.FileName)) //{ // var filePath = Path.Combine(fileStream, file.FileName); // placeVModel.image.CopyTo(fileStream); // fileStream.Flush(); //} var file = placeVModel.image; var upload = Path.Combine(_webHostEnvironment.WebRootPath, "\\uploads\\"); if (!Directory.Exists(upload)) { Directory.CreateDirectory(upload); } filePath = Path.Combine(upload, file.FileName); if (file.Length > 0) { using (var fileStream = new FileStream(filePath, FileMode.Create)) { file.CopyTo(fileStream); } } } } catch (Exception e) { } PlaceModel placeModel = new PlaceModel(); placeModel.PlaceId = placeVModel.PlaceId; placeModel.Description = placeVModel.Description; placeModel.Title = placeVModel.Title; placeModel.image = filePath; placeModel.PlaceId = placeVModel.PlaceId; placeModel.UserId = placeVModel.UserId; _context.Places.Add(placeModel); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPlaceModel", new { id = placeModel.PlaceId }, placeModel)); }
public void Create(PlaceVm vm) { Place place = new Place(); place.Name = vm.Name; place.CostPerHour = vm.CostPerHour; place.Address = vm.Address; place.PlaceTypeId = vm.PlaceTypeId; PlaceDb.Create(place); }
public void Edit(PlaceVm vm) { Place place = new Place(); place.Id = vm.Id; place.Name = vm.Name; place.CostPerHour = vm.CostPerHour; place.Address = vm.Address; place.PlaceTypeId = vm.PlaceTypeId; PlaceDb.Edit(place); }
public ActionResult Edit(PlaceVm vm) { try { var model = new Place(); model.Edit(vm); return(RedirectToAction("Index")); } catch (Exception ex) { return(View("Error")); } }
public IActionResult AddRoute(PlaceVm a) { Place b = new Place() { PlaceId = a.PlaceVmId, PlaceName = a.PlaceName }; _context.Places.Add(b); _context.SaveChanges(); ModelState.Clear(); return(View()); }
// GET: Place/Edit/5 public ActionResult Edit(int id) { var row = PlaceDb.GetPlaceById(id).Rows[0]; PlaceVm vm = new PlaceVm(); vm.Id = id; vm.Name = row["Name"].ToString(); vm.Address = row["Address"].ToString(); vm.CostPerHour = (decimal)row["CostPerHour"]; vm.PlaceTypeId = (int)row["PlaceTypeId"]; vm.PlaceTypes = GetAllPlaceTypes(); return(View(vm)); }
public IActionResult UpdateRoute(PlaceVm a) { Place p = new Place() { PlaceName = a.PlaceName, PlaceId = a.PlaceVmId, }; _context.Places.Update(p); _context.SaveChanges(); return(RedirectToAction("RouteList")); }
public ActionResult Create(PlaceVm vm) { try { if (!ModelState.IsValid) { return(View()); } var model = new Place(); model.Create(vm); return(RedirectToAction("Index")); } catch (Exception ex) { return(View("Error")); } }
public IActionResult UpdateRoute(int id) { if (HttpContext.Session.GetString("UserRole") == "1") { var item = _context.Places.AsNoTracking().Where(s => s.PlaceId == id).FirstOrDefault(); PlaceVm p = new PlaceVm() { PlaceName = item.PlaceName, PlaceVmId = item.PlaceId, }; return(View(p)); } else { return(RedirectToAction("Index", "Home")); } }