Example #1
0
        public Task<IHttpActionResult> PutTransaction([FromODataUri] Guid id, [FromODataUri] Guid itemId, SaleLineItem item, ODataQueryOptions<SaleLineItem> options)
        {
            if (!ModelState.IsValid)
            {
                return Task.FromResult((IHttpActionResult)BadRequest(ModelState));
            }

            if (itemId != item.Id)
            {
                return Task.FromResult((IHttpActionResult)BadRequest("The Id of item does not match the itemId"));
            }

            var items = this.database.SaleLineItems.Where(r => r.Id == itemId && r._SaleHeaderId == id);

            return PutOrPatchODataAsync(items, options,
                () =>
                {
                    item._SaleHeaderId = id;
                    return item.CreateAsync(this.database, this.database.SaleLineItems);
                },
                () =>
                {
                    item._SaleHeaderId = id;
                    return item.UpdateAsync(this.database, this.database.SaleLineItems);
                });
        }
Example #2
0
        public async Task<IHttpActionResult> PostTransaction([FromODataUri] Guid id, SaleLineItem item)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            item._SaleHeaderId = id;
            return Created(await item.CreateAsync(this.database, this.database.SaleLineItems));
        }
Example #3
0
 private static void CompareChanged(SaleLineItem transaction, JToken token)
 {
     CompareChangedCommon(transaction, token);
     Assert.AreEqual(transaction.ProductName, (string)token["ProductName"]);
     Assert.AreNotEqual(transaction.ProductDescription, (string)token["ProductDescription"]);
     Assert.AreEqual(transaction.Quantity, (int)token["Quantity"]);
     Assert.AreEqual(transaction.UnitPrice, (decimal)token["UnitPrice"]);
     Assert.AreEqual(transaction.Status, (SaleStatus)Enum.Parse(typeof(SaleStatus), (string)token["Status"]));
     CompareOpenProperties(transaction.DynamicProperties, token);
 }
Example #4
0
 private static void GetSaleLineItemAndETag(out SaleLineItem transaction, out string etag)
 {
     transaction = GetSaleLineItem();
     var tag = default(string);
     ODataClientHelper.InvokeGet(string.Format("{0}Sales({1})/Items({2})", SalesServiceRootUrl, transaction._SaleHeaderId, transaction.Id),
         null,
         response =>
         {
             var json = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
             var obj = JObject.Parse(json);
             tag = (string)obj["@odata.etag"];
             return false;
         });
     etag = tag;
 }
Example #5
0
        public void TestInitialize()
        {
            TestCleanup();

            var totalNumber = default(int);
            using (var db = new SaleDbContext())
            {
                if (db.SaleHeaders.Any())
                {
                    totalNumber = db.SaleHeaders.Max(s => s.TotalNumber);
                }
            }

            var sales = new List<SaleHeader>(55);

            for (int i = 0; i < sales.Capacity; i++)
            {
                var now = GenerateFakeNow();
                var random = new Random(i);

                var sale = new SaleHeader()
                {
                    DayNumber = sales.Count(s => s.Created.Date == now.Date) + 1,
                    TotalNumber = totalNumber + i + 1,
                    SalesPersonName = GenerateSalesPersonName(i),
                    CustomerName = string.Format("customer {0}", i + 1),
                    Status = GenerateEnumValue<SaleStatus>(),
                };
                sale.NumberText = sale.GenerateSaleNumber();
                sale.CustomerContacts = new[]
                {
                    new Contact()
                    {
                        Method = ContactMethod.Phone,
                        Value = string.Format("contact method phone number {0}", i + 1),
                    },
                    new Contact()
                    {
                        Method = GenerateEnumValue<ContactMethod>(),
                        Value = string.Format("contact method {0}", i + 1),
                    },
                };
                sale.Items = new List<SaleLineItem>();
                var length = random.Next(1, 5);
                for (int j = 0; j < length; j++)
                {
                    var line = new SaleLineItem()
                    {
                        ProductName = GenerateProductName(),
                        ProductDescription = null,
                        Quantity = random.Next(1, 2),
                        UnitPrice = (decimal)((random.NextDouble() + 0.1) * 10000),
                        Status = GenerateEnumValue<SaleStatus>(),
                    };
                    if (j % 2 == 0)
                    {
                        line.DynamicProperties.Add("Certificate", GenerateCertificate());
                        line.DynamicProperties.Add("Cut", GenerateCut());
                        line.DynamicProperties.Add("Caret", GenerateCaret());
                        line.DynamicProperties.Add("Color", GenerateColor());
                        line.DynamicProperties.Add("Clarity", GenerateClarity());
                    }

                    sale.Items.Add(line);
                }

                FillCommonValues(sale, now);

                sales.Add(sale);
            }

            using (var db = new SaleDbContext())
            {
                db.SaleHeaders.AddRange(sales);
                db.SaleLineItems.AddRange(sales.SelectMany(s => s.Items));
                db.Contacts.AddRange(sales.SelectMany(s => s.CustomerContacts));
                db.SaveChanges();
            }
        }