예제 #1
0
        public async Task<HttpResponseMessage> PostSaleInfo(SaleInfo sale)
        {
            JObject result = new JObject();            
            try
            {
                if (!ModelState.IsValid)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                if (sale.Image == null || Methods.CheckExpiredDateOfSasQuery(sale.SasQuery))
                {
                    var table = new SqlParameter("@table", "viethung_paybayservice.SaleInfo");
                    int saleId = Convert.ToInt32(Methods.GetInstance().GetValue("viethung_paybayservice.sp_GetMaxId", CommandType.StoredProcedure, ref Methods.err, table));
                    ModelBlob blob = await Methods.GetInstance().GetSasAndImageUriFromBlob("sales", sale.Title, saleId + 1);

                    if (blob != null)
                    {
                        sale.Image = blob.ImageUri;
                        sale.SasQuery = blob.SasQuery;
                    }
                }
                db.SaleInfoes.Add(sale);
                await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }

            result = JObject.FromObject(sale);
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }
예제 #2
0
        public async Task<HttpResponseMessage> PutSaleInfo(SaleInfo sale)
        {
            JObject result = new JObject();            
            try
            {
                if (!ModelState.IsValid)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                if (sale.Image == null || Methods.CheckExpiredDateOfSasQuery(sale.SasQuery))
                {
                    ModelBlob blob = await Methods.GetInstance().GetSasAndImageUriFromBlob("sales", sale.Title, sale.SaleId);

                    if (blob != null)
                    {
                        sale.Image = blob.ImageUri;
                        sale.SasQuery = blob.SasQuery;
                    }
                }
                db.Entry(sale).State = EntityState.Modified;
                await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }

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