Esempio n. 1
0
        public IActionResult PutProductImage(int id, ProductImage productImage)
        {
            if (id != productImage.Id)
            {
                return(BadRequest());
            }

            try
            {
                productImageService.Update(productImage);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductImageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        private void SaveImages(ProductImage item)
        {
            switch (item.ActionType)
            {
            case ActionType.Create:
            {
                _productImageService.Add(item);
                break;
            }

            case ActionType.Update:
            {
                _productImageService.Update(item);
                break;
            }

            case ActionType.Delete:
            {
                if (item.ID > 0)
                {
                    _productImageService.Remove(item);
                }
                break;
            }
            }
        }
Esempio n. 3
0
 public ActionResult <ProductImage> Put(int id, [FromBody] ProductImage ProductImage)
 {
     if (id < 1 || id != ProductImage.ID)
     {
         return(BadRequest("Parameter ID and address ID must be the same."));
     }
     _ProductImageService.Update(ProductImage);
     return(Ok("Address was successfully updated."));
 }
Esempio n. 4
0
        public JsonResult Edit(ProductImage model)
        {
            try
            {
                if (model.ProductImageId > 0)
                {
                    var entity = _ProductImageService.GetById(model.ProductImageId);

                    //修改
                    entity.BaseImageId = model.BaseImageId;
                    entity.Type        = model.Type;

                    model.EditPersonId = Loginer.AccountId;
                    model.EditTime     = DateTime.Now;
                    _ProductImageService.Update(model);
                    return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //if (_ProductImageService.CheckBusinessName(model.Name) > 0)
                    //    return Json(new { Status = Successed.Repeat }, JsonRequestBehavior.AllowGet);
                    //添加
                    model.Status         = (int)EnabledEnum.效;
                    model.IsDelete       = (int)IsDeleteEnum.效;
                    model.CreatePersonId = Loginer.AccountId;
                    model.CreateTime     = DateTime.Now;
                    model.EditPersonId   = Loginer.AccountId;
                    model.EditTime       = DateTime.Now;
                    model = _ProductImageService.Insert(model);
                    if (model.ProductImageId > 0)
                    {
                        return(Json(new { Status = Successed.Ok }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Status = Successed.Error }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 5
0
        public IActionResult Update([FromForm(Name = ("Image"))] IFormFile file, [FromForm(Name = ("Id"))] int Id)
        {
            var productImage = _productImageService.GetById(Id).Data;
            var result       = _productImageService.Update(file, productImage);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Esempio n. 6
0
        public IActionResult Update([FromForm(Name = ("Image"))] IFormFile file, [FromForm] ProductImage carImage)
        {
            var result = _productImageService.Update(file, carImage);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
Esempio n. 7
0
        public async Task <IActionResult> UpdateProductImage(int productId, [FromForm] ProductImageRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _productImageService.Update(productId, request);

            if (!result.IsSuccessed)
            {
                return(BadRequest(result.Message));
            }
            return(Ok());
        }
Esempio n. 8
0
        public async Task <IActionResult> Update([FromBody] ProductImageViewModel productImageVm)
        {
            var hasPermission = await _authorizationService.AuthorizeAsync(User, "PRODUCT", Operations.Update);

            if (hasPermission.Succeeded == false)
            {
                return(new BadRequestObjectResult(CommonConstants.Forbidden));
            }
            if (ModelState.IsValid)
            {
                _productImageService.Update(productImageVm);
                _productImageService.SaveChanges();
                return(new OkObjectResult(productImageVm));
            }
            return(new BadRequestObjectResult(ModelState));
        }
 public HttpResponseMessage Update(HttpRequestMessage request, ProductImageViewModel productImageVm)
 {
     return(CreateHttpResponse(request, () =>
     {
         if (ModelState.IsValid)
         {
             ProductImage productImageDb = _productImageService.GetByID(productImageVm.ID);
             productImageDb.UpdateProductImage(productImageVm);
             _productImageService.Update(productImageDb);
             _productImageService.Save();
             return request.CreateResponse(HttpStatusCode.OK, productImageVm);
         }
         else
         {
             return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
     }));
 }
        public ActionResult Create(ProductImageModel model)
        {
            var admin = UserInfo.CurrentUserName;

            if (ModelState.IsValid)
            {
                var resultModel = new ResultModel();
                if (model.ProductImageId != 0)
                {
                    model.UpdateBy = admin;
                    model.UpdateDT = DateTime.Now;
                    model.linkUrl  = !string.IsNullOrEmpty(model.linkUrl) && model.linkUrl.Length > 7 && model.linkUrl.Contains("http://") ? model.linkUrl : string.Empty;
                    var result = _productImageService.Update(model);
                    resultModel.Messages = new List <string>
                    {
                        result.Data > 0 ? "Modify product picture success" : "Modify product picture failed"
                    };
                    var opera = string.Format("修改产品图:{0},操作结果:{1}", JsonConverts.ToJson(model), result.Data > 0 ? "成功" : "失败");
                    LogPackage.InserAC_OperateLog(opera, "企业信息--产品图");
                }
                else
                {
                    model.ProductImageId = MemCacheFactory.GetCurrentMemCache().Increment("commonId");
                    model.CreateBy       = admin;
                    model.CreateDT       = DateTime.Now;
                    model.UpdateBy       = admin;
                    model.UpdateDT       = DateTime.Now;
                    model.linkUrl        = !string.IsNullOrEmpty(model.linkUrl) && model.linkUrl.Length > 7 && model.linkUrl.Contains("http://") ? model.linkUrl : string.Empty;
                    model.place          = MemCacheFactory.GetCurrentMemCache().Increment("commonId");
                    resultModel.Messages = new List <string>
                    {
                        _productImageService.Add(model).Messages.Count == 0 ? "Add product picture success" : "Add product picture failed"
                    };
                }
                return(Json(resultModel, JsonRequestBehavior.AllowGet));
            }
            else
            {
                DrowList(null);
            }
            return(PartialView(model));
        }