public async Task <bool> MakeUserActive(int id) { try { IQueryable <User> query = context.Users; query = query.Where(u => u.UserID == id); var usr = query.First(); usr.IsActive = true; context.Update(usr); await context.SaveChangesAsync(); return(true); } catch { return(false); } }
/// <summary> /// Saves all changes in db /// </summary> /// <returns></returns> public async Task <bool> SaveChangesAsync() { try { return((await context.SaveChangesAsync()) > 0); } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.InnerException); return(false); } }
public async Task <IActionResult> PutFullAddress(int id, FullAddress fullAddress) { int x = 0; DbUpdateConcurrencyException exception = null; if (id != fullAddress.FullAddressID) { return(BadRequest()); } _context.Entry(fullAddress).State = EntityState.Modified; try { x = await _context.SaveChangesAsync(); // } catch (DbUpdateConcurrencyException ex) { //exception = ex; if (!FullAddressExists(id)) { return(NotFound()); } else { throw ex; } } if (x > 0) { return(Ok()); } else if (exception != null) { return(StatusCode(500, "internal server error" + exception.Message + exception.InnerException)); } else { return(NoContent()); } }
public async Task <bool> AddAddress(FullAddress address) { try { await context.AddAsync <FullAddress>(address); if (await context.SaveChangesAsync() > 0) { return(true); } else { return(false); } } catch (Exception ex) { Debug.WriteLine(ex.Message + ex.InnerException); return(false); } }
public async Task <bool> AddLocation(Location location) { try { context.Add(location); int x = await context.SaveChangesAsync(); if (x == 1) { return(true); } else { return(false); } } catch { return(false); } }