public ActionResult <Activity> createActivity(int userId, Activity activity) { var user = _repoWrapper.User.FindById(userId); if (user == null) { return(Ok(user)); } activity.User = user; _activityRepo.CreateActivity(activity); _repoWrapper.Save(); return(Ok(activity)); }
public IActionResult CreateOrder([FromBody] Order order) { try { if (order == null) { logger.Error("order object sent from client is null."); return(BadRequest("Invalid Order")); } if (!ModelState.IsValid) { logger.Error("Invalid order object sent from client."); return(BadRequest("Invalid Order")); } var listErrors = _repositoryWrap.Order.ValidateOrder(order); if (listErrors.Count == 0) { _repositoryWrap.Order.Create(order); _repositoryWrap.Save(); return(Ok(new { id = order.Id })); } else { logger.Error("Invalid order validation " + string.Join(",", listErrors.ToArray())); return(BadRequest("Invalid order validation " + string.Join(", ", listErrors.ToArray()))); } } catch (Exception ex) { logger.Error($"Something went wrong inside CreateOrder action: {ex.Message}"); return(BadRequest("Internal server error")); } }
public ActionResult <User> RegisterUser(User createUser) { var existUser = _repoWrapper.User.ExistUser(createUser); if (existUser == true) { return(BadRequest(new { message = "Username or Password Already Exist!" })); } else { createUser.Password = EncryptMethod.ConvertToEncrypt(createUser.Password); _repoWrapper.User.Create(createUser); _repoWrapper.Save(); return(Ok(new { message = "Successfully Registered!" })); } }