public IActionResult Get(string email) { Cloud.Result <Wppod.Models.User> result = new Cloud.Result <Wppod.Models.User>(); try { Wppod.Models.User user = _cafeContext.Users.FirstOrDefault( searchUser => searchUser.Email == email); if (user == null) { result.SetFail("User not found"); } else { result.SetSuccess("user", user); } } catch (System.Exception e) { result.SetFail(e, "Query"); } return(Ok(result)); }
public async Task <IActionResult> CreateAsync( [FromBody] Wppod.Models.User user) { Cloud.Result <Wppod.Models.User> result = new Cloud.Result <Wppod.Models.User>(); try { if (!ModelState.IsValid) { result.SetFail("Invalid model state"); } else { string status = string.Format("User Create request, received by Nest-{0}.{1} at {2}", _runtime.NestTag, _runtime.CushionIndex, DateTime.Now.ToString("t")); _logger.LogInformation(status); _cafeContext.Users.Add(user); await _cafeContext.SaveChangesAsync(); result.SetSuccess("user", user); } } catch (System.Exception e) { result.SetFail(e, "CreateAsync"); } return(Ok(result)); }
public async Task <IActionResult> CreateOrderAsync( long user_id, [FromBody] Order order) { Cloud.Result <Order> result = new Cloud.Result <Order>(); try { if (!ModelState.IsValid) { result.SetFail("Invalid model state"); } else { _logger.LogInformation(string.Format( "Order Create request from user id {0} received by Nest-{1}.{2} at {3}. {4}", user_id, _runtime.NestTag, _runtime.CushionIndex, DateTime.Now.ToString("t"), JsonConvert.SerializeObject(order))); Wppod.Models.User user = _cafeContext.Users.FirstOrDefault( searchUser => searchUser.Id == user_id); if (user == null) { result.SetFail("User not found"); } else { order.User = user; _cafeContext.Orders.Add(order); await _cafeContext.SaveChangesAsync(); result.SetSuccess("order", order); } } } catch (System.Exception e) { result.SetFail(e, "CreateOrderAsync"); } return(Ok(result)); }