示例#1
0
        public async Task<HttpResponseMessage> PutBill(Bill bill)
        {
            JObject result = new JObject();
            if (!ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
            }
                        
            db.Entry(bill).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BillExists(bill.BillId))
                {
                    result = Methods.CustomResponseMessage(0, "Bill isn't exists!");
                    return Request.CreateResponse(HttpStatusCode.NotFound, result);
                }
                else
                {
                    throw;
                }
            }

            result = JObject.FromObject(bill);
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }
示例#2
0
        public async Task<HttpResponseMessage> PostBill(Bill bill)
        {
            JObject result = new JObject();            
            try
            {
                if (!ModelState.IsValid)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                db.Bills.Add(bill);
                await db.SaveChangesAsync();

                //var createDate = new SqlParameter("@CreatedDate", bill.CreatedDate);
                var store = new SqlParameter("@StoreID", bill.StoreID);
                //var total = new SqlParameter("@TotalPrice", bill.TotalPrice);
                //var reduce = new SqlParameter("@ReducedPrice", bill.ReducedPrice);
                var user = new SqlParameter("@UserID", bill.UserID);
                //var shipMethod = new SqlParameter("@ShipMethod", bill.ShipMethod);
                //var trade = new SqlParameter("@TradeTerm", bill.TradeTerm);
                //var agree = new SqlParameter("@Agree", bill.AgreeredShippingDate);
                //var shipDate = new SqlParameter("@ShipDate", bill.ShippingDate);

                //var response = Methods.GetInstance().ExecQueryWithResult("viethung_paybayservice.sp_AddBill", CommandType.StoredProcedure, ref Methods.err,
                //                  createDate, store, total, reduce, user, shipMethod, trade, agree, shipDate);

                var response = Methods.GetInstance().ExecQueryWithResult("viethung_paybayservice.sp_GetUserJustOrder", CommandType.StoredProcedure, ref Methods.err, store, user);

                if (response.Count > 0)
                    result = response[0].ToObject<JObject>();

                await PushHelper.SendToastAsync(WebApiConfig.Services, result["Username"].ToString() + " just order to you!","You have new order!"
                                                    ,new Uri(result["Avatar"].ToString()), result["OwnerID"].ToString());
            }
            catch (Exception ex)
            {
                result = Methods.CustomResponseMessage(0, "Submit bill is not successful!");
                return Request.CreateResponse(HttpStatusCode.BadRequest, result);
            }

            result = JObject.FromObject(bill);            
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }