public async Task <IActionResult> Upsert(int?id) { CampingPark obj = new CampingPark(); if (id == null) { // this will be true for insert/create return(View(obj)); } // this will come here for update. obj = await _cpRepo.GetAsync(StaticDetails.CampingParkAPIPath, id.GetValueOrDefault(), HttpContext.Session.GetString("JWToken")); if (obj == null) { return(NotFound()); } return(View(obj)); }
public async Task <IActionResult> Upsert(CampingPark obj) { if (ModelState.IsValid) { var files = HttpContext.Request.Form.Files; if (files.Count > 0) { byte[] p1 = null; using (var _fileStream = files[0].OpenReadStream()) { using (var _memoryStream = new MemoryStream()) { _fileStream.CopyTo(_memoryStream); p1 = _memoryStream.ToArray(); } } obj.Picture = p1; } else { var objFromDb = await _cpRepo.GetAsync(StaticDetails.CampingParkAPIPath, obj.Id, HttpContext.Session.GetString("JWToken")); obj.Picture = objFromDb.Picture; } if (obj.Id == 0) { await _cpRepo.CreateAsync(StaticDetails.CampingParkAPIPath, obj, HttpContext.Session.GetString("JWToken")); } else { await _cpRepo.UpdateAsync(StaticDetails.CampingParkAPIPath + obj.Id, obj, HttpContext.Session.GetString("JWToken")); } return(RedirectToAction(nameof(Index))); } else { return(View(obj)); } }
public bool DeleteCampingPark(CampingPark cPark) { _context.CampingParks.Remove(cPark); return(Save()); }
public bool UpdateCampingPark(CampingPark cPark) { _context.CampingParks.Update(cPark); return(Save()); }
public bool CreateCampingPark(CampingPark cPark) { _context.CampingParks.Add(cPark); return(Save()); }