public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams) { Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetMaxAge(TimeSpan.Zero); JObject inputData = null; try { using (StreamReader reader = new StreamReader(Request.InputStream)) { using (JsonTextReader jsonReader = new JsonTextReader(reader)) { inputData = JObject.Load(jsonReader); } } } catch { RespondBadRequest(Response); } Int64 AppUserId; if (IsAuthorizedRequest(Request, Response, true, out AppUserId)) { Response.ContentType = @"application/json"; JToken jt; Int64? product_id = null; if (inputData.TryGetValue(@"product_id", out jt)) { product_id = jt.Value <Int64>(); } using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream)) { using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter)) { ProductYad2 productYad2 = ProductYad2.FetchByID(product_id); if (productYad2 == null) { RespondNotFound(Response); } productYad2.UpdateDate = DateTime.UtcNow; productYad2.Save(); jsonWriter.WriteStartObject(); jsonWriter.WriteEndObject(); } } } }
public static void DenyProduct(Int64 ProductId, String StatusRemarks, String message) { ProductYad2 product = ProductYad2.FetchByID(ProductId); if (product != null) { product.Status = StatusType.Denied; product.StatusRemarks = StatusRemarks; product.UpdateDate = DateTime.UtcNow; product.Save(); Notification.SendNotificationDenyProduct(product.AppUserId, product.ProductId, message); } }
public override void Post(HttpRequest Request, HttpResponse Response, params string[] PathParams) { Response.Cache.SetCacheability(HttpCacheability.NoCache); Int64 AppUserId; if (IsAuthorizedRequest(Request, Response, true, out AppUserId)) { Response.ContentType = @"text/plain"; // IE<=9 can't parse JSON when content type is any different than text/plain string sub_folder = Request.Form["sub_folder"] != null ? Request.Form["sub_folder"].ToString() : ""; string fn = null; if (Request.Files.Count == 1) { if (!IsAcceptedImageExtension(Request.Files[0].FileName)) { RespondUnauthorized(Response); } fn = MediaUtility.SaveFile(Request.Files[0], sub_folder, (sub_folder == @"Animal" ? AppUserId : 0)); if (string.IsNullOrEmpty(fn)) { RespondInternalServerError(Response); } } Int64 ProductId = Request.Form["product_id"] != null?Convert.ToInt64(Request.Form["product_id"]) : 0; Int32 w = Request.Form["w"] != null?Convert.ToInt32(Request.Form["w"]) : 0; Int32 h = Request.Form["h"] != null?Convert.ToInt32(Request.Form["h"]) : 0; if (sub_folder == @"Animal") { AppUserAnimal animal = AppUserAnimal.FetchByID(AppUserId); MediaUtility.DeleteImageFilePath(sub_folder, animal.AnimalImg, w, h, AppUserId); animal.AnimalImg = fn; animal.Save(); } else if (sub_folder == @"Product") { Product p = Product.FetchByID(ProductId); MediaUtility.DeleteImageFilePath(sub_folder, p.ProductImage, w, h, 0); p.ProductImage = fn; p.Save(); } else if (sub_folder == @"ProductYad2") { ProductYad2 p = ProductYad2.FetchByID(ProductId); MediaUtility.DeleteImageFilePath(sub_folder, p.ProductImage, w, h, 0); p.ProductImage = fn; p.Save(); } if (!string.IsNullOrEmpty(fn)) { using (StreamWriter streamWriter = new StreamWriter(Response.OutputStream)) { using (JsonTextWriter jsonWriter = new JsonTextWriter(streamWriter)) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("file_name"); jsonWriter.WriteValue(fn); //jsonWriter.WritePropertyName("preview"); //jsonWriter.WriteValue(MediaUtility.GetImageFilePath(AppUserId, @"Animal",HttpUtility.UrlEncode(fn),64,64)); //jsonWriter.WritePropertyName("url"); //jsonWriter.WriteValue(MediaUtility.GetOriginalFilePath(AppUserId, @"Animal",HttpUtility.UrlEncode(fn))); jsonWriter.WriteEndObject(); } } } else { RespondInternalServerError(Response); } } }