コード例 #1
0
        public async Task <IHttpActionResult> PutCustomer(Guid id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.Id)
            {
                return(BadRequest());
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public async Task <IHttpActionResult> PutItem(int id, Item item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != item.Id)
            {
                return(BadRequest());
            }

            db.Entry(item).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public async Task <IHttpActionResult> PostOrder(OrderViewModel order)
        {
            Order dbOrder = new Order();

            dbOrder.Id         = Guid.NewGuid();
            dbOrder.CustomerId = order.OrderInfo.CustomerId;
            Decimal num1 = new Decimal();

            foreach (EBillAppTest.Models.Item obj in order.Items)
            {
                EBillAppTest.Models.Item item = obj;
                db.OrderItems.Add(new OrderItem()
                {
                    Id       = Guid.NewGuid(),
                    OrderId  = dbOrder.Id,
                    ItemId   = item.Id,
                    Quantity = new int?(item.Quantity)
                });
                var itemType = db.ItemTypes.SingleOrDefault(it => it.ItemId == item.Id && it.TypeId == (int)item.Type);
                if (itemType != null)
                {
                    num1 += itemType.Amount * (Decimal)item.Quantity;
                }
            }
            dbOrder.Amount      = num1;
            dbOrder.OrderNumber = "OD" + string.Format("{0:d9}", (object)(DateTime.Now.Ticks / 10L % 1000000000L));
            db.Orders.Add(dbOrder);
            try
            {
                int num2 = await db.SaveChangesAsync();
            }
            catch (DbUpdateException ex)
            {
                if (OrderExists(dbOrder.Id))
                {
                    return(Conflict());
                }
                throw;
            }
            var    customer = db.Customers.SingleOrDefault(cust => cust.Id == dbOrder.CustomerId);
            string email    = customer.Email;
            string from     = "*****@*****.**";
            await EmailHelper.SendEmailAsync(EmailContentHelper.GenerateContent(TableBuilder.BuildTable(order), dbOrder.OrderNumber, dbOrder.Amount, customer.FirstName + " " + customer.LastName), from, email, dbOrder.OrderNumber);

            return(Ok(new
            {
                status = "success"
            }));
        }