public async Task <HttpResponseMessage> UploadImage() { var ctx = HttpContext.Current; var root = ctx.Server.MapPath("~/Images"); var provider = new MultipartFormDataStreamProvider(root); List <string> ImagesPath = new List <string>(); HandelError <string> HandelImage = new HandelError <string>(); try { await Request.Content.ReadAsMultipartAsync(provider); foreach (var file in provider.FileData) { string datemilli = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds().ToString(); var name = file.Headers.ContentDisposition.FileName; name = datemilli + name.Trim('"'); var localfilename = file.LocalFileName; var filepath = Path.Combine(root, name); //ImagesID.Add(SavaFilePath(localfilename, filepath)); var ImagePath = "http://gerges96-001-site1.dtempurl.com/Images/" + name; ImagesPath.Add(ImagePath); File.Move(localfilename, filepath); if (File.Exists(localfilename)) { File.Delete(localfilename); } } HandelImage.data = ImagesPath; HandelImage.status = true; HandelImage.message = ""; return(Request.CreateResponse(HttpStatusCode.OK, HandelImage)); } catch (Exception e) { HandelImage.data = null; HandelImage.status = false; HandelImage.message = e.Message; return(Request.CreateResponse(HttpStatusCode.NotFound, HandelImage)); } }
public IHttpActionResult GetItemsByCategoryID(int id) { List <ItemModel> item = db.Items.Where(c => c.Cat_ID == id).Where(a => a.Approval == true).ToList().Select(c => mf.create(c)).ToList(); HandelError <ItemModel> handelError = new HandelError <ItemModel>(); if (item.Count() > 0) { handelError.data = item; handelError.status = true; handelError.message = ""; return(Ok(handelError)); } else { handelError.data = null; var message = string.Format("Category with id = {0} not found", id); handelError.status = false; handelError.message = message; return(Ok(handelError)); } }
// GET: api/Categories public HttpResponseMessage GetCategories() { HandelError <CategoryModel> handelError = new HandelError <CategoryModel>(); var categories = db.Categories.ToList().Select(c => mf.create(c)); if (categories.Count() > 0) { handelError.data = categories; handelError.status = true; handelError.message = ""; return(Request.CreateResponse(HttpStatusCode.OK, handelError)); } else { handelError.data = null; var message = string.Format("Don't found any categories"); handelError.status = false; handelError.message = message; return(Request.CreateResponse(HttpStatusCode.NotFound, handelError)); } }
public IHttpActionResult GetItemsFilter(int?id = null, int?typeID = null, int?genderID = null) { List <ItemModel> item = db.Items.Where(x => x.Cat_ID == id && (typeID == null || x.Type_ID == typeID)).ToList().Select(c => mf.create(c)).ToList(); //List<ItemModel> item = db.Items.Include(b => b.Genders).Where(x => x.Cat_ID == id && (typeID == null || x.Type_ID == typeID) && (genderID == null || x.Genders.Select(d => d.Gender_ID).FirstOrDefault() == genderID)).ToList().Select(c => mf.create(c)).ToList(); HandelError <ItemModel> handelError = new HandelError <ItemModel>(); if (item.Count() > 0) { handelError.data = item; handelError.status = true; handelError.message = ""; return(Ok(handelError)); } else { handelError.data = null; var message = string.Format("Category with id = {0} not found", id); handelError.status = false; handelError.message = message; return(Ok(handelError)); } }