public void PostOrders() { // Login var userList = So.GetAllUsers(); Assert.IsTrue(userList != null && userList.Count > 0); var newItem = new Item {ProductId = 1, CreatedDateTime = DateTime.UtcNow}; newItem.ItemSelectedOptions.Add(new ItemSelectedOption { OptionChoiceId = 3 }); newItem.ItemSelectedOptions.Add(new ItemSelectedOption { OptionChoiceId = 7 }); newItem.ItemSelectedOptions.Add(new ItemSelectedOption { OptionChoiceId = 10 }); var newOrder = new Order { ExpectedArrivalDateTime = DateTime.UtcNow.Add(TimeSpan.FromMinutes(10)), OrderedDateTime = DateTime.UtcNow, PickupDateTime = DateTime.UtcNow.Add(TimeSpan.FromMinutes(10)), StoreBranchId = 1 }; newOrder.Items.Add(newItem); var returnedOrder = So.SubmitNewOrder(newOrder); Assert.IsNotNull(returnedOrder); Assert.IsFalse(string.IsNullOrEmpty(returnedOrder.ReferenceNumber)); Assert.IsTrue(returnedOrder.Id > 0); }
public Order SubmitNewOrder(Order newOrder) { if (string.IsNullOrEmpty(ToSavourToken)) { throw new InvalidOperationException("No ToSavour Token is set"); } RequestClient = new WebClient(); RequestClient.Headers.Add("Authorization", ToSavourToken); RequestClient.Headers.Add("Content-Type", "application/json"); var memoryStream = new MemoryStream(); GetSerializer(typeof(Order)).WriteObject(memoryStream, newOrder); memoryStream.Position = 0; var sr = new StreamReader(memoryStream); var json = sr.ReadToEnd(); var userJsonString = RequestClient.UploadString(_host + @"orders", json); var byteArray = Encoding.ASCII.GetBytes(userJsonString); var stream = new MemoryStream(byteArray); var returnedOrder = GetSerializer(typeof(Order)).ReadObject(stream) as Order; return returnedOrder; }
public Order SubmitNewOrder(Order newOrder) { if (_userId == Guid.Empty) { HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return null; } if (newOrder.Items.Count == 0) { HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.Forbidden; return null; } newOrder.UserId = _userId; var stringChars = ReferenceCodeGenerator(); newOrder.ReferenceNumber = stringChars; newOrder.Status = "pending"; foreach (var item in newOrder.Items) { item.Status = "pending"; } _dbContext.Orders.Add(newOrder); _dbContext.SaveChanges(); var returnedOrder = _dbContext.Orders.OrderByDescending(o => o.OrderedDateTime) .FirstOrDefault(o => o.UserId == newOrder.UserId); if (returnedOrder == null) { // Something went wrong, the recently saved Order history was not able to be retrieved from database. Log@@@ HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.InternalServerError; return null; } return returnedOrder; }
public void PopulateOrder() { var newItem = new Item { ProductId = 1, CreatedDateTime = DateTime.UtcNow, Status = "pending"}; newItem.ItemSelectedOptions.Add(new ItemSelectedOption { OptionChoiceId = 3 }); newItem.ItemSelectedOptions.Add(new ItemSelectedOption { OptionChoiceId = 7 }); newItem.ItemSelectedOptions.Add(new ItemSelectedOption { OptionChoiceId = 10 }); var newOrder = new Order { ExpectedArrivalDateTime = DateTime.UtcNow.Add(TimeSpan.FromMinutes(10)), OrderedDateTime = DateTime.UtcNow, PickupDateTime = DateTime.UtcNow.Add(TimeSpan.FromMinutes(10)), Status = "pending", ReferenceNumber = "ZXSDEW", UserId = new Guid("17D7232C-D95B-448A-B9C9-05FD58365CB7"), StoreBranchId = 1 }; newOrder.Items.Add(newItem); _dbContext.Orders.Add(newOrder); _dbContext.SaveChanges(); }