Пример #1
0
        public async Task<HttpResponseMessage> PostMarket(Market market)
        {
            JObject result = new JObject();
            try
            {
                if (!ModelState.IsValid)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                if (market.Image == null || Methods.CheckExpiredDateOfSasQuery(market.SasQuery))
                {
                    var table = new SqlParameter("@table", "viethung_paybayservice.Markets");
                    int marketId = Convert.ToInt32(Methods.GetInstance().GetValue("viethung_paybayservice.sp_GetMaxId", CommandType.StoredProcedure, ref Methods.err, table));
                    ModelBlob blob = await Methods.GetInstance().GetSasAndImageUriFromBlob("markets", market.MarketName, marketId + 1);

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

            result = JObject.FromObject(market);
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }
Пример #2
0
        public async Task<HttpResponseMessage> PutMarket(Market market)
        {
            JObject result = new JObject();
            try
            {
                if (!ModelState.IsValid)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                if (market.Image == null || Methods.CheckExpiredDateOfSasQuery(market.SasQuery))
                {
                    ModelBlob blob = await Methods.GetInstance().GetSasAndImageUriFromBlob("markets", market.MarketName, market.MarketId);

                    if (blob != null)
                    {
                        market.Image = blob.ImageUri;
                        market.SasQuery = blob.SasQuery;
                    }
                }
                db.Entry(market).State = EntityState.Modified;
                await db.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                result = Methods.CustomResponseMessage(0, "Update market is not successful!");
                return Request.CreateResponse(HttpStatusCode.BadRequest, result);
            }

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