Пример #1
0
        public HttpResponseMessage ImageForSanPhamById(HttpRequestMessage request, int id)
        {
            SanPham sanPhamSingler = null;

            try
            {
                sanPhamSingler = _sanPhamService.GetById(id);
                if (sanPhamSingler != null)
                {
                    if (sanPhamSingler.HinhAnhSanPhams.ToList().Count > 0)
                    {
                        sanPhamSingler.HinhAnhChinh = sanPhamSingler.HinhAnhSanPhams.ToList().First().LinkHinhAnh;
                        _sanPhamService.Update(sanPhamSingler);
                        _sanPhamService.SaveChange();
                    }
                    Message = "Thông tin sản phẩm với id: " + id;
                }
                else
                {
                    throw new DbEntityValidationException(string.Format("Không tìm kiếm được sản phẩm với id {0}", id));
                }
            }
            catch (DbEntityValidationException ex)
            {
                LogException(ex);
            }
            return(GetResponseMessage(IsSuccess, Message, 1, sanPhamSingler));
        }
Пример #2
0
        public IActionResult ChinhSua(
            SanPhamViewModel model, IFormFile AnhDaiDien,
            IFormCollection fc,
            IFormFile productImages1,
            IFormFile productImages2,
            IFormFile productImages3)
        {
            model.MaSp = fc["MaSp"];
            SanPhamViewModel a = _spService.GetById(fc["MaSp"]);

            if (AnhDaiDien == null)
            {
                model.AnhDaiDien = a.AnhDaiDien;
            }
            else
            {
                model.AnhDaiDien = FileHelper.UploadedFile(AnhDaiDien, "ProductAvatar");
            }
            if (ModelState.IsValid)
            {
                model.Ishot  = Convert.ToBoolean(fc["isHot"].ToString().Split(',')[0]);
                model.Isnew  = Convert.ToBoolean(fc["isNew"].ToString().Split(',')[0]);
                model.Status = fc["status"].ToString().Contains("on") ? 1 : 0;
                _spService.Update(model, fc["MaSp"]);
                AnhSanPhamViewModel pic = _aspService.GetByIdSp(model.MaSp);
                if (productImages1 != null)
                {
                    pic.Anh1 = FileHelper.UploadedFile(productImages1, "ProductImages");
                }
                if (productImages2 != null)
                {
                    pic.Anh2 = FileHelper.UploadedFile(productImages2, "ProductImages");
                }
                if (productImages3 != null)
                {
                    pic.Anh3 = FileHelper.UploadedFile(productImages3, "ProductImages");
                }

                _aspService.UpdateAnhSP(pic);

                foreach (var tskt in _tsktService.GetThongSoKiThuat(model.MaSp))
                {
                    tskt.GiaTri = fc[tskt.ThongSo];
                    _tsktService.UpdateTSKT(tskt);
                }
                _spService.SaveChange();
                return(RedirectToAction("QuanLy", "Admin", new { id = model.LoaiSp }).WithSuccess("Thành công", "Sản phẩm đã được sửa. ID: " + model.MaSp));
            }
            else
            {
                return(View(model));
            }
        }
Пример #3
0
 public HttpResponseMessage Create(HttpRequestMessage request, SAN_PHAM sanPhamModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var thuongHieu = _sanPhamService.Add(sanPhamModel);
             _sanPhamService.SaveChange();
             response = request.CreateResponse(HttpStatusCode.Created, thuongHieu);
         }
         return response;
     }));
 }