コード例 #1
0
 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()));
     }
 }
コード例 #2
0
 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()));
     }
 }
コード例 #3
0
 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));
     }
 }
コード例 #4
0
ファイル: ClothingLogic.cs プロジェクト: MiryamOrbach/test
        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);
        }