public async Task <bool> UpdateObjectForRent(ObjectForRent objectForRent) { _context.Entry(_context.ObjectForRent.FirstOrDefault(c => c.ObjectForRentId == objectForRent.ObjectForRentId)).CurrentValues.SetValues(objectForRent); if (await _context.SaveChangesAsync() > 0) { return(true); } return(false); }
public async Task <bool> AddObjectForRent(ObjectForRent objectForRent) { await _context.AddAsync(objectForRent); if (await _context.SaveChangesAsync() > 0) { return(true); } return(false); }
public async Task <IActionResult> AddOrEdit(ObjectForRent objectForRent) { string Message; if (ModelState.IsValid) { //Insert if (objectForRent.ObjectForRentId == 0) { await _objectForRentRepositorytory.AddObjectForRent(objectForRent); Message = "Dodano obiekt"; } //Update else { bool value = await _objectForRentRepositorytory.UpdateObjectForRent(objectForRent); if (value == false) { return(NotFound()); } Message = "Edycja rezerwacji przebiegła pomyślnie"; } var Objects = await _objectForRentRepositorytory.GetObjectForRents(); return(Json(new { html = Helper.RenderRazorViewToString(this, "ObjectForRentList", Objects), message = Message, style = "success" })); } else { Message = "Wprowadz poprawne dane"; var Objects = await _objectForRentRepositorytory.GetObjectForRents(); return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "ObjectForRentList", Objects), message = Message, style = "error" })); } }