public override ServiceResult <ProductEntity> Add(ProductEntity item) { var result = base.Add(item); if (result.HasViolation) { return(result); } if (item.ProductTags != null) { _productTagService.BeginBulkSave(); foreach (var tag in item.ProductTags.Where(m => m.Selected)) { _productTagService.Add(new ProductTag { ProductId = item.ID, TagId = tag.ID }); } _productTagService.SaveChanges(); } if (item.ProductImages != null) { item.ProductImages.Each(m => { m.ProductId = item.ID; if (m.ActionType == ActionType.Create) { _productImageService.Add(m); } }); } return(result); }
public async Task <IActionResult> Add([FromForm] ProductCreateDto productCreateDto) { var entity = await _productService.Add(productCreateDto); if (entity.Success) { if (productCreateDto.ProductImages != null) { var resimler = Path.Combine(_environment.WebRootPath, "productImage");//dizin bilgisi List <string> images = new List <string>(); foreach (var item in productCreateDto.ProductImages) { //if (item.Image.Length > 0) // { string imageName = $"{Guid.NewGuid().ToString()}.jpg";//Db ye kaydedilecek olan resimlerin ismi using (var fileStream = new FileStream(Path.Combine(resimler, imageName), FileMode.Create)) { images.Add(imageName); await item.CopyToAsync(fileStream); } // } } var saveImage = await _productImageService.Add(images, entity.Data.Id); if (saveImage.Success) { return(Ok(entity.Message)); } return(BadRequest("Resimler yüklenirken hata oluştu")); } return(Ok(entity.Message)); } return(BadRequest()); }
public HttpResponseMessage Create(HttpRequestMessage request, ProductImageViewModel productImageVm) { if (ModelState.IsValid) { var newImage = new ProductImage(); var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; try { newImage.UpdateProductImage(productImageVm); _productImageService.Add(newImage); _productImageService.Save(); Log log = new Log() { AppUserId = claims.FirstOrDefault().Value, Content = Notification.CREATE_PRODUCTIMG, Created = DateTime.Now }; _logService.Create(log); _logService.Save(); return(request.CreateResponse(HttpStatusCode.OK, productImageVm)); } catch (Exception dex) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message)); } } else { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public ActionResult AddImage(Product product) { if (Request.Files.Count > 0 && !string.IsNullOrWhiteSpace(Request.Files[0].FileName)) { _productImageService.Add(Request.Files, product); } return(RedirectToAction("AddImage", new { @id = product.Id })); }
public override ServiceResult <ProductEntity> Add(ProductEntity item) { ServiceResult <ProductEntity> result = new ServiceResult <ProductEntity>(); if (item.Url.IsNotNullAndWhiteSpace()) { if (GetByUrl(item.Url) != null) { result.RuleViolations.Add(new RuleViolation("Url", _localize.Get("URL already exists"))); return(result); } } _eventManager.Trigger(Events.OnProductAdding, item); BeginTransaction(() => { result = base.Add(item); if (!result.HasViolation) { if (item.ProductTags != null) { _productTagService.BeginBulkSave(); foreach (var tag in item.ProductTags.Where(m => m.Selected)) { _productTagService.Add(new ProductTag { ProductId = item.ID, TagId = tag.ID }); } _productTagService.SaveChanges(); } if (item.ProductImages != null) { item.ProductImages.Each(m => { m.ProductId = item.ID; if (m.ActionType == ActionType.Create) { _productImageService.Add(m); } }); } } }); _eventManager.Trigger(Events.OnProductAdded, item); return(result); }
public IActionResult Add([FromForm(Name = ("Image"))] IFormFile file, [FromForm] ProductImage productImage) { var result = _productImageService.Add(file, productImage); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult Add(ProductViewModel productViewModel) { if (ModelState.IsValid) { var productIsValid = _productService.GetByName(productViewModel.Product.Name); if (productIsValid != null) { return(RedirectToAction("GetProducts")); } var productForAdd = new Product { AddedDate = DateTime.Now, AddedBy = "Merih Can Korkmaz", CategoryId = productViewModel.Product.CategoryId, Explanation = productViewModel.Product.Explanation, Height = productViewModel.Product.Height, Name = productViewModel.Product.Name, Weight = productViewModel.Product.Weight, Width = productViewModel.Product.Width }; try { var addedProduct = _productService.Add(productForAdd); if (productViewModel.FormFiles != null) { foreach (var image in productViewModel.FormFiles) { var uniqueFileName = Guid.NewGuid().ToString() + "_" + image.FileName; var filePath = Path.DirectorySeparatorChar.ToString() + "ProductImages" + Path.DirectorySeparatorChar.ToString() + uniqueFileName; var upLoadsFolder = Path.Combine(_env.WebRootPath, "ProductImages"); var filePathForCopy = Path.Combine(upLoadsFolder, uniqueFileName); image.CopyTo(new FileStream(filePathForCopy, FileMode.Create)); var productImageForAdd = new ProductImage { AddedBy = "merih", AddedDate = DateTime.Now, ProductId = addedProduct.Id, FileName = uniqueFileName, FilePath = filePath }; _productImageService.Add(productImageForAdd); } } return(RedirectToAction("GetProducts")); } catch (Exception) { return(RedirectToAction("GetProducts")); } } return(RedirectToAction("GetProducts")); }
public override ServiceResult <ProductEntity> Add(ProductEntity item) { if (item.Url.IsNotNullAndWhiteSpace()) { if (GetByUrl(item.Url) != null) { var re = new ServiceResult <ProductEntity>(); re.RuleViolations.Add(new RuleViolation("Url", "UrlÒÑ´æÔÚ")); return(re); } } var result = base.Add(item); if (result.HasViolation) { return(result); } if (item.ProductTags != null) { _productTagService.BeginBulkSave(); foreach (var tag in item.ProductTags.Where(m => m.Selected)) { _productTagService.Add(new ProductTag { ProductId = item.ID, TagId = tag.ID }); } _productTagService.SaveChanges(); } if (item.ProductImages != null) { item.ProductImages.Each(m => { m.ProductId = item.ID; if (m.ActionType == ActionType.Create) { _productImageService.Add(m); } }); } return(result); }
public override void Add(ProductEntity item) { base.Add(item); if (item.ProductTags != null) { foreach (var tag in item.ProductTags.Where(m => m.Selected)) { _productTagService.Add(new ProductTag { ProductId = item.ID, TagId = tag.ID }); } } if (item.ProductImages != null) { item.ProductImages.Each(m => { m.ProductId = item.ID; if (m.ActionType == ActionType.Create) { _productImageService.Add(m); } }); } }
public async Task <IActionResult> Add([FromBody] ProductImageViewModel productImageVm) { var hasPermission = await _authorizationService.AuthorizeAsync(User, "PRODUCT", Operations.Create); if (hasPermission.Succeeded == false) { return(new BadRequestObjectResult(CommonConstants.Forbidden)); } if (ModelState.IsValid) { _productImageService.Add(productImageVm); _productImageService.SaveChanges(); return(new OkObjectResult(productImageVm)); } return(new BadRequestObjectResult(ModelState)); }
public HttpResponseMessage Create(HttpRequestMessage request, ProductImageViewModel productImageVm) { return(CreateHttpResponse(request, () => { if (ModelState.IsValid) { ProductImage productImageDb = new ProductImage(); productImageDb.UpdateProductImage(productImageVm); _productImageService.Add(productImageDb); _productImageService.Save(); return request.CreateResponse(HttpStatusCode.OK, productImageVm); } else { return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } })); }
// [Permission(Action = ActionName.CanCreate)] public IHttpActionResult CreateProductImage([FromBody] ProductImageDto productImage) { return(CreateResponse(() => { if (!ModelState.IsValid) { return BadRequest(ModelState); } var model = Mapper.Map <ProductImage>(productImage); _productImageService.Add(model); UnitOfWork.Commit(); productImage.Id = model.Id; return Created(new Uri(Request.RequestUri + "/" + productImage.Id), productImage); })); }
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)); }
public HttpResponseMessage Create(HttpRequestMessage request, ProductImageViewModel productImageVm) { if (ModelState.IsValid) { var model = new ProductImage(); try { model.UpdateProductImage(productImageVm); _productImageService.Add(model); _productImageService.Save(); return(request.CreateResponse(HttpStatusCode.OK, productImageVm)); } catch (Exception ex) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } } else { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public async Task <IActionResult> Add([FromForm] ImageCreateDto imageCreateDto) { var resimler = Path.Combine(_environment.WebRootPath, "productImage");//dizin bilgisi List <string> images = new List <string>(); foreach (var item in imageCreateDto.ProductImages) { string imageName = $"{Guid.NewGuid().ToString()}.jpg";//Db ye kaydedilecek olan resimlerin ismi using (var fileStream = new FileStream(Path.Combine(resimler, imageName), FileMode.Create)) { images.Add(imageName); await item.CopyToAsync(fileStream); } } var saveImage = await _productImageService.Add(images, imageCreateDto.ProductId); if (saveImage.Success) { return(Ok(saveImage.Message)); } return(BadRequest()); }