public HttpResponseMessage GetCloth(int id) { try { ClothingModel cloth = clothingLogic.GetOneCloth(id); return(Request.CreateResponse(HttpStatusCode.OK, cloth)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.GetUsreFriendlyMessage())); } }
public HttpResponseMessage AddCloth(ClothingModel cloth) { try { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetAllErrors())); } cloth = clothingLogic.AddCloth(cloth); return(Request.CreateResponse(HttpStatusCode.Created, cloth)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.GetUsreFriendlyMessage())); } }
public HttpResponseMessage UploadImage() { try { int clothingId = int.Parse(HttpContext.Current.Request.Form["clothingId"]); string originalName = HttpContext.Current.Request.Files[0].FileName; string newFileName = Guid.NewGuid().ToString() + Path.GetExtension(originalName); string fullPathAndFileName = HttpContext.Current.Server.MapPath("~/Images/" + newFileName); HttpContext.Current.Request.Files[0].SaveAs(fullPathAndFileName); ClothingModel cloth = clothingLogic.saveImage(clothingId, newFileName); return(Request.CreateResponse(HttpStatusCode.Created, cloth)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ClothingModel AddCloth(ClothingModel model) { Clothing cloth = new Clothing { CategoryId = model.category.id, CompanyId = model.company.id, TypeId = model.type.id, Price = model.price, Discount = model.discount, Image = model.image }; DB.Clothes.Add(cloth); DB.SaveChanges(); model.id = cloth.Id; return(model); }