コード例 #1
0
        public BrandCategoryModel MapToModel(BrandCategory item)
        {
            var newItem = Mapper.Map <BrandCategory, BrandCategoryModel>(item);

            newItem.BrandCount = item.BrandBrandCategories.Count();
            return(newItem);
        }
コード例 #2
0
        public BrandCategory[] GetOffersModelPrice()
        {
            try
            {
                using (var bpEntity = new BrandOutletMonitoringEntities())
                {
                    var cellPhonePricingList = bpEntity.BrandMonitorCategories.ToList();

                    var list = new List <BrandCategory>();

                    foreach (var brandMonitorCategory in cellPhonePricingList)
                    {
                        var br = new BrandCategory();
                        br.name = brandMonitorCategory.Name;
                        br.type = brandMonitorCategory.Type;
                        br.id   = brandMonitorCategory.Id.ToString();
                        list.Add(br);
                    }



                    return(list.ToArray());
                }
            }
            catch (Exception ex)
            {
                throw new CultureNotFoundException("Error Occured While Getting Information");
            }
        }
コード例 #3
0
        public HttpResponseMessage Post([FromBody] BrandCategory brandcategory)
        {
            try
            {
                if (brandcategory == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Data is not finded at request body !"));
                }
                else
                {
                    db.BrandCategory.Add(brandcategory);

                    if (db.SaveChanges() > 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, brandcategory));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"BrandCategory is not added !"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex));
            }
        }
コード例 #4
0
        public Error InsertOrUpdateBrandCategory(BrandCategoryModel category,
                                                 List <int> selectedBrandIds,
                                                 UserModel user, string lockGuid)
        {
            var error = validateModel(category);

            if (!error.IsError)
            {
                // Check that the lock is still current
                if (!db.IsLockStillValid(typeof(BrandCategory).ToString(), category.Id, lockGuid))
                {
                    error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "CategoryName");
                }
                else
                {
                    BrandCategory temp = null;
                    if (category.Id != 0)
                    {
                        temp = db.FindBrandCategory(category.Id);
                    }
                    if (temp == null)
                    {
                        temp = new BrandCategory();
                    }

                    Mapper.Map <BrandCategoryModel, BrandCategory>(category, temp);

                    db.InsertOrUpdateBrandCategory(temp, selectedBrandIds);
                    category.Id = temp.Id;
                }
            }
            return(error);
        }
コード例 #5
0
        public JsonResult AddBrandCategory(string Name, string description = "")
        {
            try
            {
                using (var db = new PolishWarehouseEntities())
                {
                    var br = db.BrandCategories.Where(b => b.Name == Name).SingleOrDefault();
                    if (br != null)
                    {
                        throw new Exception("Category already exists!");
                    }

                    var category = new BrandCategory()
                    {
                        Name        = Name,
                        Description = description
                    };

                    db.BrandCategories.Add(category);
                    db.SaveChanges();
                    return(Json(category.ID));
                }
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }
コード例 #6
0
        public async Task <IActionResult> CreateBrandCategory(int categoryId, int brandId)
        {
            var category = await _repository.GetCategory(categoryId);

            if (category == null)
            {
                return(BadRequest("Invalid Category Id"));
            }
            var brand = await _repository.GetBrand(brandId);

            if (brand == null)
            {
                return(BadRequest("Invalid Brand Id"));
            }
            var brandCat = new BrandCategory {
                CategoryId = categoryId,
                BrandId    = brandId
            };

            if (await _repository.EntityExists(brandCat))
            {
                return(BadRequest("The Brand Id already belongs to this category"));
            }
            _repository.Add(brandCat);
            if (await _repository.SaveAllChangesAsync())
            {
                return(Ok("Successfully created brand Category"));
            }
            return(BadRequest("An Error occurred while creating brand category"));
        }
コード例 #7
0
        public async Task <ActionResult <BrandCategory> > PostBrandCategory(BrandCategory brandCategory)
        {
            _context.BrandCategory.Add(brandCategory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBrandCategory", new { id = brandCategory.Id }, brandCategory));
        }
コード例 #8
0
        public async Task <IActionResult> PutBrandCategory(int id, BrandCategory brandCategory)
        {
            brandCategory.Id = id;
            if (id <= 0)
            {
                return(BadRequest());
            }

            _context.Entry(brandCategory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BrandCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #9
0
        public async Task <IActionResult> Edit(int id, [Bind("BrandCategoryId,BrandName")] BrandCategory brandCategory)
        {
            if (id != brandCategory.BrandCategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(brandCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BrandCategoryExists(brandCategory.BrandCategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(brandCategory));
        }
コード例 #10
0
ファイル: BrandService.cs プロジェクト: hancheester/apollo
        public BrandCategory GetBrandCategoryByUrlKey(string brandCategoryUrlKey)
        {
            BrandCategory brandCategory = _brandCategoryRepository.Table
                                          .FirstOrDefault(b => b.UrlRewrite == brandCategoryUrlKey);

            return(brandCategory);
        }
コード例 #11
0
        public void EditBrandCategory(BrandCategory brandCategory)
        {
            var editedBrandCategory = _context.BrandCategory.First(x => x.ID == brandCategory.ID);

            editedBrandCategory.Name = brandCategory.Name;
            _context.Entry(editedBrandCategory).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.SaveChanges();
        }
コード例 #12
0
        public async Task <IActionResult> Create([Bind("BrandCategoryId,BrandName")] BrandCategory brandCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(brandCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brandCategory));
        }
コード例 #13
0
 public ActionResult Delete(int id)
 {
     using (HISDBEntities db = new HISDBEntities())
     {
         BrandCategory bcg = db.BrandCategories.Where(x => x.CategoryID == id)
                             .FirstOrDefault <BrandCategory>();
         db.BrandCategories.Remove(bcg);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
コード例 #14
0
 public async Task <bool> EntityExists <T>(T entityName) where T : class
 {
     if (entityName is Product)
     {
         Product product = entityName as Product;
         if (await _context.Products.AnyAsync(b => b.Name == product.Name && b.StoreId == product.StoreId))
         {
             return(true);
         }
         return(false);
     }
     else if (entityName is Merchant)
     {
         Merchant customer = entityName as Merchant;
         if (await _context.Merchants.AnyAsync(b => b.Name == customer.Name))
         {
             return(true);
         }
         return(false);
     }
     else if (entityName is Store)
     {
         Store store = entityName as Store;
         if (await _context.Stores.AnyAsync(b => b.Name == store.Name && b.Location == store.Location))
         {
             return(true);
         }
         return(false);
     }
     else if (entityName is Category)
     {
         Category category = entityName as Category;
         if (await _context.Categories.AnyAsync(b => b.Name == category.Name))
         {
             return(true);
         }
         return(false);
     }
     else if (entityName is BrandCategory)
     {
         BrandCategory category = entityName as BrandCategory;
         if (await _context.BrandCategory.AnyAsync(b => b.CategoryId == category.CategoryId && b.BrandId == category.BrandId))
         {
             return(true);
         }
         return(false);
     }
     else
     {
         return(false);
     }
 }
コード例 #15
0
ファイル: BrandService.cs プロジェクト: hancheester/apollo
 private BrandCategoryOverviewModel BuildBrandCategoryOverviewModel(BrandCategory brandCategory)
 {
     return(new BrandCategoryOverviewModel
     {
         Id = brandCategory.Id,
         Name = brandCategory.Name,
         ParentId = brandCategory.ParentId,
         BrandId = brandCategory.BrandId,
         Description = brandCategory.Description,
         ImageUrl = brandCategory.ImageUrl,
         UrlKey = brandCategory.UrlRewrite
     });
 }
コード例 #16
0
        public HttpResponseMessage PutCategory([FromBody] BrandCategory brandcategory, [FromUri] String cid = null)
        {
            int res;

            if (Int32.TryParse(cid, out res) == true)
            {
                return(PutForBrandCategoryToCategoryId(res, brandcategory));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Parameter is not valid !Please use Category Id (bid = {cid}) "));
            }
        }
コード例 #17
0
        public async Task <IActionResult> Post([FromBody] BrandCategory entity)
        {
            var exists = await _repo.GetAll()
                         .FirstOrDefaultAsync(x => x.CategoryId == entity.CategoryId & x.BrandId == entity.BrandId);

            if (exists != null)
            {
                return(BadRequest($"This relation already exists: {entity}"));
            }
            await _repo.Create(entity);

            await _repo.Save();

            return(StatusCode(201, entity));
        }
コード例 #18
0
        private void PopulateBrandCategoryInfo(int brandCategoryId)
        {
            BrandCategory brandCategory = BrandService.GetBrandCategoryById(brandCategoryId);

            if (brandCategory != null)
            {
                txtName.Text   = Server.HtmlDecode(brandCategory.Name);
                txtDesc.Text   = Server.HtmlDecode(brandCategory.Description);
                txtUrlKey.Text = brandCategory.UrlRewrite;

                if (brandCategory.ImageUrl == string.Empty)
                {
                    imgThumbnail.Visible  = false;
                    cbRemoveThumb.Visible = false;
                }
                else
                {
                    imgThumbnail.Src      = "/get_image_handler.aspx?type=brand&img=" + brandCategory.ImageUrl;
                    imgThumbnail.Visible  = true;
                    cbRemoveThumb.Visible = true;
                }

                cbVisible.Checked = brandCategory.Visible;
                hfParent.Value    = brandCategory.ParentId.ToString();

                if (brandCategory.ParentId != AppConstant.DEFAULT_BRAND_CATEGORY)
                {
                    ltlParent.Text = BrandService.GetBrandCategoryById(brandCategory.ParentId).Name;
                }
            }

            SetState(BRAND_CATEGORY_ID, brandCategoryId);

            if (GetIntState(BRAND_CATEGORY_ID) == AppConstant.DEFAULT_BRAND_CATEGORY)
            {
                SetState(MODE, NEW);
                SetState(CHOSEN_FILTER, ANY);
            }
            else
            {
                SetState(MODE, EDIT);
                SetState(CHOSEN_FILTER, YES);
            }

            LoadProducts();

            hfCurrentPanel.Value = "general";
        }
コード例 #19
0
 public ActionResult AddModify(BrandCategory bcg)
 {
     using (HISDBEntities db = new HISDBEntities())
     {
         if (bcg.CategoryID == 0)
         {
             db.BrandCategories.Add(bcg);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(bcg).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
コード例 #20
0
        private HttpResponseMessage PutForBrandCategoryToCategoryId(int id, BrandCategory brandcategory)
        {
            try
            {
                if (brandcategory == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Data is not finded at request body !"));
                }
                else
                {
                    if (id <= 0)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"BrandCategory (BrandId = {id}) is not valid !"));
                    }
                    else
                    {
                        var query = db.BrandCategory.FirstOrDefault(x => x.BrandCategoryCategoryId == id);

                        if (query == null)
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"BrandCategory (BrandId = {id}) is not finded !"));
                        }
                        else
                        {
                            query.BrandCategoryCategoryId = brandcategory.BrandCategoryCategoryId;
                            query.BrandCategoryBrandId    = brandcategory.BrandCategoryBrandId;

                            if (db.SaveChanges() > 0)
                            {
                                return(Request.CreateResponse(HttpStatusCode.OK, query));
                            }
                            else
                            {
                                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"BrandCategory (BrandId = {id}) is not updated !"));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex));
            }
        }
コード例 #21
0
 public HttpResponseMessage Put([FromBody] BrandCategory brandcategory, [FromUri] int?id = 0, [FromUri] int?bid = 0, [FromUri] int?cid = 0)
 {
     if (id >= 1)
     {
         return(PutForBrandCategoryToId(id.Value, brandcategory));
     }
     else if (bid >= 1)
     {
         return(PutForBrandCategoryToBrandId(bid.Value, brandcategory));
     }
     else if (cid >= 1)
     {
         return(PutForBrandCategoryToCategoryId(cid.Value, brandcategory));
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $"Parameter is not valid !Please use BrandCategory Id(id = {id}) or Brand Id (bid = {bid}) or Category Id (cid = {cid})"));
     }
 }
コード例 #22
0
 public HttpResponseMessage Delete([FromBody] BrandCategory brandcategory, [FromUri] int?id = 0, [FromUri] int?bid = 0, [FromUri] int?cid = 0)
 {
     if (brandcategory == null)
     {
         if (id.Value >= 1)
         {
             return(DeleteForBrandCategoryToId(id.Value));
         }
         else if (bid >= 1)
         {
             return(DeleteForBrandCategoryToBrandId(bid.Value));
         }
         else if (cid >= 1)
         {
             return(DeleteForBrandCategoryToCategoryId(cid.Value));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"Parameter is not valid !Please use BrandCategoryId (id = {id}) or BrandId (bid = {bid}) or CategoryId (cid = {cid}) ."));
         }
     }
     else
     {
         if (brandcategory.BrandCategoryId >= 1)
         {
             return(DeleteForBrandCategoryToId(brandcategory.BrandCategoryId));
         }
         else if (brandcategory.BrandCategoryBrandId >= 1)
         {
             return(DeleteForBrandCategoryToBrandId(brandcategory.BrandCategoryBrandId));
         }
         else if (brandcategory.BrandCategoryCategoryId >= 1)
         {
             return(DeleteForBrandCategoryToCategoryId(brandcategory.BrandCategoryCategoryId));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, $"Parameter is not valid !Please use BrandCategoryId (id = {brandcategory.BrandCategoryId}) or BrandId (bid = {brandcategory.BrandCategoryBrandId}) or CategoryId (cid = {brandcategory.BrandCategoryCategoryId}) ."));
         }
     }
 }
コード例 #23
0
        //Get contact by ID
        public BrandCategory GetBrandCategory(int categoryID)
        {
            BrandCategory brandCategory = null;

            using (HISDBEntities dc = new HISDBEntities())
            {
                var v = (from a in dc.BrandCategories
                         join b in dc.Brands on a.BrandID equals b.BrandID
                         where a.CategoryID.Equals(categoryID)
                         select new
                {
                    a,
                    b.BrandName,
                }).FirstOrDefault();
                if (v != null)
                {
                    brandCategory           = v.a;
                    brandCategory.BrandName = v.BrandName;
                }
                return(brandCategory);
            }
        }
コード例 #24
0
 public MenuModel(BrandCategory category)
 {
     Category = category;
     Name     = CategoryHelper.GetCategoryName(category);
 }