public IActionResult Get(string name = null)
        {
            BrandBO      brandBO;
            List <Brand> brands;
            ObjectResult response;

            try
            {
                _log.LogInformation("Starting Get()");

                brandBO = new BrandBO(_loggerFactory, _config);
                brands  = brandBO.Get(name);

                response = Ok(brands);

                _log.LogInformation($"Finishing Get() with '{brands.Count}' results");
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                response = StatusCode(500, ex.Message);
            }

            return(response);
        }
        public IActionResult Get(int id)
        {
            BrandBO      brandBO;
            Brand        brand;
            ObjectResult response;

            try
            {
                _log.LogInformation($"Starting Get( {id} )");

                brandBO = new BrandBO(_loggerFactory, _config);

                brand = brandBO.Get(id);

                if (brand != null)
                {
                    response = Ok(brand);
                }
                else
                {
                    response = NotFound(string.Empty);
                }

                _log.LogInformation($"Finishing Get( {id} )");
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                response = StatusCode(500, ex.Message);
            }

            return(response);
        }
        public IActionResult Put(int id, Brand brand)
        {
            BrandBO      brandBO;
            ObjectResult response;

            try
            {
                _log.LogInformation($"Starting Put( {id}, '{JsonConvert.SerializeObject(brand, Formatting.None)}')");

                brandBO = new BrandBO(_loggerFactory, _config);

                brand.ID = id;
                brand    = brandBO.Update(brand);

                response = Ok(brand);

                _log.LogInformation($"Finishing Put( {id} )");
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                response = StatusCode(500, ex.Message);
            }

            return(response);
        }
        public IActionResult Post([FromBody] Brand brand)
        {
            BrandBO      brandBO;
            ObjectResult response;

            try
            {
                _log.LogInformation($"Starting Post('{JsonConvert.SerializeObject(brand, Formatting.None)}')");

                brandBO = new BrandBO(_loggerFactory, _config);

                brand = brandBO.Insert(brand);

                response = Ok(brand);

                _log.LogInformation($"Finishing Post");
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                response = StatusCode(500, ex.Message);
            }

            return(response);
        }
        public ActionResult UpdateBrand(int id = 0)
        {
            BrandBO model = new BrandBO();

            if (id > 0)
            {
                model = BrandModel.GetBrandByID(id);
            }
            return(View(model));
        }
        public ActionResult UpdateBrand(BrandBO brandModel)
        {
            if (ModelState.IsValid)
            {
                UserLogin user         = (UserLogin)Session[CommonConstants.USER_SESSION];
                string    errorMessage = "";
                bool      result       = false;
                brandModel.isdeleted = 0;
                if (brandModel.id > 0)
                {
                    //get updatemodel
                    BrandBO newUpdateBO = new BrandBO();
                    newUpdateBO = BrandModel.GetBrandByID(brandModel.id);
                    if (newUpdateBO == null)
                    {
                        ModelState.AddModelError("", "Brand không tồn tại");
                        return(View(brandModel));
                    }

                    newUpdateBO.updateduser     = user.UserID.ToString();
                    newUpdateBO.updateddate     = DateTime.Now;
                    newUpdateBO.description     = brandModel.description;
                    newUpdateBO.isdeleted       = 0;
                    newUpdateBO.keyword         = brandModel.keyword;
                    newUpdateBO.logo            = brandModel.logo;
                    newUpdateBO.metadescription = brandModel.metadescription;
                    newUpdateBO.metakeyword     = brandModel.metakeyword;
                    newUpdateBO.name            = brandModel.name;
                    newUpdateBO.seoname         = brandModel.seoname;

                    result = BrandModel.UpdateBrand(newUpdateBO, ref errorMessage);
                    SetAlert($"Cập nhật Brand {brandModel.id}-{brandModel.name} thành công", "success");
                }
                else
                {
                    brandModel.createduser = user.UserID.ToString();
                    brandModel.createddate = DateTime.Now;
                    result = BrandModel.InsertBrand(brandModel, ref errorMessage);
                    SetAlert($"Thêm Brand {brandModel.name} thành công", "success");
                }

                if (result)
                {
                    return(RedirectToAction("Brand", "Category"));
                }
                else
                {
                    ModelState.AddModelError("", "Có lỗi xảy ra. Thêm thất bại: " + errorMessage);
                }
            }

            return(View(brandModel));
        }
示例#7
0
 public ActionResult CreateBrand(long id)
 {
     if (_session.IsLogin && _session.IsStore && _session.IsAdmin)
         {
             vw_Brand model = new vw_Brand();
             ViewBag.ID = id;
             if(id!=-1)
             {
                 IBrand cls = new BrandBO();
                 model = cls.GetData(_session.LangID, id);
             }
             return View(model);
         }
         else
             return RedirectToAction("index", "admin");
 }
示例#8
0
        public static bool InsertBrand(BrandBO brandModel, ref string errorMessage)
        {
            try
            {
                //tao id: lay id max hien tai+1
                brandModel.id = GetMaxBrandID() + 1;

                var collection = MongoClientHelper.Current.ConnectDatabase().GetCollection <BrandBO>("brand");

                collection.InsertOne(brandModel);
                return(true);
            }
            catch (Exception ex)
            {
                errorMessage = ex.ToString();
                return(false);
            }
        }
示例#9
0
        public static bool UpdateBrand(BrandBO brandModel, ref string errorMessage)
        {
            try
            {
                var collection    = MongoClientHelper.Current.ConnectDatabase().GetCollection <BrandBO>("brand");
                var filterBuilder = Builders <BrandBO> .Filter;
                var filter        = filterBuilder.Eq("id", brandModel.id);

                var result = collection.ReplaceOne(filter, brandModel);
                if (result.IsAcknowledged)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                errorMessage = ex.ToString();
                return(false);
            }
        }
        public IActionResult Delete(int id)
        {
            BrandBO      brandBO;
            ObjectResult response;

            try
            {
                _log.LogInformation($"Starting Delete( {id} )");

                brandBO = new BrandBO(_loggerFactory, _config);
                brandBO.Delete(id);

                response = Ok(string.Empty);

                _log.LogInformation($"Finishing Delete( {id} )");
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                response = StatusCode(500, ex.Message);
            }

            return(response);
        }
示例#11
0
 public JsonResult SaveBrand(Brand brand, BrandLang brandLang)
 {
     if (_session.IsLogin && _session.IsStore && _session.IsAdmin)
         {
             brand.SiteID = _session.SiteID;
             brandLang.LangID = _session.LangID;
             IBrand _cls = new BrandBO();
             var IsResult = _cls.Save(brand, brandLang);
             return Json(new { IsOk = IsResult }, JsonRequestBehavior.AllowGet);
         }
         else
             RedirectToAction("index", "admin");
         return Json("[]", JsonRequestBehavior.AllowGet);
 }
示例#12
0
 public JsonResult GetBrand()
 {
     string jsonData = "[]";
         IBrand _cls = new BrandBO();
         var data = _cls.GetData(_session.LangID);
         if (data != null)
             jsonData = new JavaScriptSerializer().Serialize(data);
         return Json(jsonData, JsonRequestBehavior.AllowGet);
 }
示例#13
0
 public JsonResult DeleteBrand(long id)
 {
     if (_session.IsLogin && _session.IsStore && _session.IsAdmin)
         {
             IBrand _cls = new BrandBO();
             var IsResult = _cls.Delete(id);
             return Json(new { IsOk = IsResult }, JsonRequestBehavior.AllowGet);
         }
         else
             RedirectToAction("index", "admin");
         return Json(new { IsOk = false }, JsonRequestBehavior.AllowGet);
 }