Ejemplo n.º 1
0
        public async Task<HttpResponseMessage> PutStore(Store store)
        {
            JObject result = new JObject();            
            try
            {
                if (!ModelState.IsValid)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                if (store.Image == null || Methods.CheckExpiredDateOfSasQuery(store.SasQuery))
                {                    
                    ModelBlob blob = await Methods.GetInstance().GetSasAndImageUriFromBlob("stores", store.StoreName, store.StoreId);

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

            result = JObject.FromObject(store);
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }
Ejemplo n.º 2
0
        public async Task<HttpResponseMessage> PostStore(Store store)
        {
            JObject result = new JObject();            
            try
            {
                if (!ModelState.IsValid)
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                if (store.Image == null || Methods.CheckExpiredDateOfSasQuery(store.SasQuery))
                {
                    var table = new SqlParameter("@table", "viethung_paybayservice.Stores");
                    int storeId = Convert.ToInt32(Methods.GetInstance().GetValue("viethung_paybayservice.sp_GetMaxId", CommandType.StoredProcedure, ref Methods.err, table));
                    ModelBlob blob = await Methods.GetInstance().GetSasAndImageUriFromBlob("stores", store.StoreName, storeId + 1);

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

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