public ActionResult Update(BrandViewModel model)
        {
            if (ModelState.IsValid)
            {
                var brandDb = this.Mapper.Map<Brand>(model);
                this.brands.Update(brandDb);
                this.brands.SaveChanges();

                this.HttpContext.Cache.Remove("menu");
            }

            return RedirectToAction("Index");
        }
        /// <summary>
        /// 品牌列表頁 (首頁)
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            BrandViewModel viewModel = new BrandViewModel();

            // 產品總數
            viewModel.productCounter = _productRepository.RetrieveCount(true);

            // 產品類型
            viewModel.brandTypeList = _brandTypeRepository.GetList(false);

            // 品牌列表
            viewModel.brandList = _brandRepository.GetList(0, 0, false);

            return View(viewModel);
        }
        public ActionResult Add(BrandViewModel brandViewModel, bool fromClientPage = false)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    brandViewModel.CreatedBy = this.GetUserName();
                    brandViewModel.CreatedDate = DateTime.Now;
                    
                    var brand = AutoMapper.Mapper.Map<BikeStore.Models.Brand>(brandViewModel);
                    db.Brands.Add(brand);
                    db.SaveChanges();
                    if (fromClientPage)
                    {
                        return Json(brand.BrandID, JsonRequestBehavior.AllowGet); 
                    }
                    else
                    {
                        return RedirectToAction("Index");
                    }
                }
                catch(DbUpdateException ex)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);

                    if (ex.IsUniqueConstraintViolation())
                    {
                        ModelState.AddModelError("", App_GlobalResources.ErrorMessages.BrandNameExists);
                    }
                    else
                    {
                        ModelState.AddModelError("", App_GlobalResources.ErrorMessages.BrandNameCreationError);
                    }
                }
                catch (Exception ex)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);

                    ModelState.AddModelError("", App_GlobalResources.ErrorMessages.BrandNameCreationError );
                    return View();
                }
            }
            return View();
        }
示例#4
0
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(RecordNotFound());
            }
            var getOperation = await _bo.ReadAsync((Guid)id);

            if (!getOperation.Success)
            {
                return(OperationErrorBackToIndex(getOperation.Exception));
            }
            if (getOperation.Result == null)
            {
                return(RecordNotFound());
            }

            var vm = BrandViewModel.Parse(getOperation.Result);

            Draw("Details", "fa-search");

            return(View(vm));
        }
示例#5
0
        public async Task AddEditBrandPost_ReturnsARedirectAndAddBrand_WhenBrandIsValid()
        {
            // Arrange
            var brand = new BrandViewModel {
                Name = "Apple"
            };

            mockBrandRepo.Setup(x => x.InsertAsync(It.IsAny <Brand>())).Returns(Task.FromResult <Brand>(new Brand())).Verifiable();

            mockUOW.Setup(x => x.Repository <Brand>()).Returns(mockBrandRepo.Object);

            var controller = new BrandController(mockUOW.Object);

            // Act
            var result = await controller.AddEditBrand(0, brand);

            // Assert
            var redirectResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectResult.ControllerName);
            Assert.Equal("Index", redirectResult.ActionName);
            mockBrandRepo.Verify();
        }
示例#6
0
        /// <summary>
        /// Add an entity.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public BrandViewModel Add(BrandViewModel model)
        {
            this.ThrowExceptionIfExist(model);

            var entity = model.ToEntity();

            entity = this._BrandsRepository.Add(entity);

            var entityAr = new Brand
            {
                Id          = entity.Id,
                Description = model.DescriptionAr,
                Name        = model.NameAr,
                Language    = Language.Arabic
            };

            entity.ChildTranslatedBrands.Add(entityAr);
            this._BrandsRepository.Add(entityAr);

            var entityEn = new Brand
            {
                Id          = entity.Id,
                Description = model.DescriptionEn,
                Name        = model.NameEn,
                Language    = Language.English
            };

            entity.ChildTranslatedBrands.Add(entityEn);
            this._BrandsRepository.Add(entityEn);

            #region Commit Changes
            this._unitOfWork.Commit();
            #endregion

            model = entity.ToModel();
            return(model);
        }
        /// <summary>
        /// Get the list of brand by passing brand_id=0 and a single brand by passing brand_id
        /// </summary>
        /// <param name="BrandObj"></param>
        /// <returns>response object</returns>
        public async Task <ResponseViewModel <BrandViewModel> > Get(BrandViewModel BrandObj)
        {
            ResponseViewModel <BrandViewModel> ResObj = new ResponseViewModel <BrandViewModel>();

            try
            {
                if (BrandObj != null)
                {
                    InventoryDBContext dbContext = new InventoryDBContext(await connMethod.GetConnectionString(BrandObj.ConnectionString));
                    var brand = dbContext.Brand.Where(x => x.Brand_Id == BrandObj.Brand_Id || BrandObj.Brand_Id == 0).ToList();
                    if (brand.Count() > 0)
                    {
                        ResObj.Data      = JsonConvert.DeserializeObject <List <BrandViewModel> >(JsonConvert.SerializeObject(brand.ToList()));
                        ResObj.IsSuccess = true;
                    }
                    else
                    {
                        ResObj.IsSuccess    = false;
                        ResObj.ErrorCode    = 404;
                        ResObj.ErrorDetails = "No record found.";
                    }
                }
                else
                {
                    ResObj.IsSuccess    = false;
                    ResObj.ErrorCode    = 400;
                    ResObj.ErrorDetails = "Parameter not provided.";
                }
            }
            catch (Exception ex) {
                ResObj.IsSuccess    = false;
                ResObj.ErrorCode    = 500;
                ResObj.ErrorDetails = ex.ToString();
            }
            return(await Task.Run(() => { return ResObj; }));
        }
示例#8
0
        public async Task <IActionResult> InsertBrandConfirm(BrandViewModel model)
        {
            string nvm;
            var    currentUser = await userManager.FindByNameAsync(User.Identity.Name);

            try
            {
                if (!ModelState.IsValid)
                {
                    nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Wrong_Values, contentRootPath);
                    return(RedirectToAction("InsertBrand", new { notification = nvm }));
                }
                if (model != null)
                {
                    Brand brand = new Brand()
                    {
                        Name        = model.Name,
                        LatinName   = model.LatinName,
                        Description = model.Description,
                        UserId      = currentUser.Id,
                        Status      = model.Status
                    };

                    dbBrand.Insert(brand);
                    nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Success_Insert, contentRootPath);
                    return(RedirectToAction("ShowBrand", new { notification = nvm }));
                }
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Insert, contentRootPath);
                return(RedirectToAction("ShowBrand", new { notification = nvm }));
            }
            catch (Exception)
            {
                nvm = NotificationHandler.SerializeMessage <string>(NotificationHandler.Failed_Operation, contentRootPath);
                return(RedirectToAction("InsertBrand", new { notification = nvm }));
            }
        }
示例#9
0
        public async Task <ActionResult> Details(int id)
        {
            BrandsClient brandsClient = new BrandsClient();

            var brand = await brandsClient.GetByIdAsync(id);

            if (brand == null)
            {
                return(NotFound());
            }

            var result = new BrandViewModel
            {
                Id                  = brand.Id,
                BrandName           = brand.BrandName,
                ManufacturerCountry = brand.ManufacturerCountry,
                ProductClass        = brand.ProductClass,
                Rating              = brand.Rating
            };

            await brandsClient.CloseAsync();

            return(View(result));
        }
 public IActionResult Create(BrandViewModel model)
 {
     if (model == null)
     {
         return(NotFound());
     }
     if (ModelState.IsValid)
     {
         var brand = _mapper.Map <BrandViewModel, Brand>(model);
         brand.AddedBy   = _admin.Name;
         brand.AddedDate = DateTime.Now;
         if (model.File != null)
         {
             brand.Logo = _fileManager.Upload(model.File);
         }
         else
         {
             brand.Logo = null;
         }
         _aboutRepository.AddBrand(brand);
         return(RedirectToAction("index"));
     }
     return(View(model));
 }
示例#11
0
        public async Task <IActionResult> AddEditBrand(long?id)
        {
            BrandViewModel brandViewModel = new BrandViewModel();

            if (id.HasValue)
            {
                var brand = await _uow.Brands.GetAsync(id.Value);

                if (brand == null)
                {
                    _logger.LogInformation(LogMessageConstant.ItemNotFound, brandViewModel);
                    return(NotFound());
                }

                brandViewModel = _mapper.Map <BrandViewModel>(brand);
                brandViewModel.IsActiveSelectList = new SelectList(GetIsActiveSelectList(), "Value", "Text", brandViewModel.IsActive);
            }
            else
            {
                brandViewModel.IsActiveSelectList = new SelectList(GetIsActiveSelectList(), "Value", "Text", "True");
            }

            return(PartialView("~/Areas/Admin/Views/Brand/_AddEditBrand.cshtml", brandViewModel));
        }
示例#12
0
        // to get the detial of product
        public IActionResult SelectBrand(BrandViewModel brandVm)
        {
            BrandModel              brandModel          = new BrandModel(_db);
            ProductModel            prodModel           = new ProductModel(_db);
            List <Product>          productsListByBrand = prodModel.GetByBrand(brandVm.BrandId);
            List <ProductViewModel> prodVMList          = new List <ProductViewModel>();

            if (productsListByBrand.Count > 0)
            {
                // give me the details of each product by foreach loop
                foreach (Product prod in productsListByBrand)
                {
                    ProductViewModel prodVM = new ProductViewModel();

                    prodVM.QtyOnHand      = 0;
                    prodVM.BrandId        = prod.BrandId;
                    prodVM.BrandName      = brandModel.GetName(prod.BrandId);
                    prodVM.Description    = prod.Description;
                    prodVM.CostPrice      = prod.CostPrice;
                    prodVM.Id             = prod.Id;
                    prodVM.GraphicName    = prod.GraphicName;
                    prodVM.MSRP           = prod.MSRP;
                    prodVM.ProductName    = prod.ProductName;
                    prodVM.QtyOnHand      = prod.QtyOnHand;
                    prodVM.QtyOnBackOrder = prod.QtyOnBackOrder;

                    prodVMList.Add(prodVM);
                }


                ProductViewModel[] myProdArray = prodVMList.ToArray();
                HttpContext.Session.Set <ProductViewModel[]>("productSession", myProdArray);
            }
            brandVm.SetBrands(HttpContext.Session.Get <List <Brands> >("brandSession"));
            return(View("Index", brandVm));
        }
示例#13
0
        public async Task <JsonResult> OnGetCreateOrEdit(int id = 0)
        {
            var brandsResponse = await _mediator.Send(new GetAllBrandsCachedQuery());

            if (id == 0)
            {
                var brandViewModel = new BrandViewModel();
                return(new JsonResult(new { isValid = true, html = await _viewRenderer.RenderViewToStringAsync("_CreateOrEdit", brandViewModel) }));
            }
            else
            {
                var response = await _mediator.Send(new GetBrandByIdQuery()
                {
                    Id = id
                });

                if (response.Succeeded)
                {
                    var brandViewModel = _mapper.Map <BrandViewModel>(response.Data);
                    return(new JsonResult(new { isValid = true, html = await _viewRenderer.RenderViewToStringAsync("_CreateOrEdit", brandViewModel) }));
                }
                return(null);
            }
        }
示例#14
0
        public ActionResult AddOrEditBrand(Guid?id, BrandViewModel model, HttpPostedFileBase logo)
        {
            try
            {
                bool   isNew     = !id.HasValue;
                string localFile = Server.MapPath("~/Content/img/logocarousel/");

                // isNew = true update UpdatedDate of product
                // isNew = false get it by id
                var brand = isNew ? new Brand
                {
                    UpdatedDate = DateTime.Now
                } : _brandService.GetById(id.Value);

                brand.Name     = model.Name;
                brand.Summary  = model.Summary;
                brand.Logo     = _brandService.UpFile(logo, localFile);
                brand.IsActive = true;

                if (isNew)
                {
                    brand.CreatedDate = DateTime.Now;
                    brand.Id          = Guid.NewGuid();
                    _brandService.Insert(brand);
                }
                else
                {
                    _brandService.Update(brand);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index"));
        }
示例#15
0
 public ActionResult Create(BrandViewModel brandViewModel)
 {
     brandViewModel.CategoryList = _categoryBusiness.GetListWT().Select(x => new SelectListItem
     {
         Text  = x.CategoryName.ToString(),
         Value = x.CategoryId.ToString()
     }).ToList();
     if (ModelState.IsValid)
     {
         Mapper.CreateMap <BrandViewModel, Brand>();
         Brand brand  = Mapper.Map <BrandViewModel, Brand>(brandViewModel);
         var   result = _brandBusiness.ValidateBrand(brand, "I");
         if (!string.IsNullOrEmpty(result))
         {
             ModelState.AddModelError("", result);
             return(View(brandViewModel));
         }
         else
         {
             brand.TokenKey = GlobalMethods.GetToken();
             bool isSuccess = _brandBusiness.AddUpdateDeleteBrand(brand, "I");
             if (isSuccess)
             {
                 TempData["Success"]   = "Brand Created Successfully!!";
                 TempData["isSuccess"] = "true";
                 return(RedirectToAction("Index"));
             }
             else
             {
                 TempData["Success"]   = "Failed to create Brand!!";
                 TempData["isSuccess"] = "false";
             }
         }
     }
     return(View(brandViewModel));
 }
示例#16
0
        public async Task <IActionResult> Put([FromForm] BrandViewModel model)
        {
            string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;


            var editedBrand = await _brandService.EditBrandAsync(model.Id, model.Name, userId);

            if (editedBrand != null)
            {
                return(Ok(new OperationResponse <Brand>
                {
                    IsSuccess = true,
                    Message = $"{editedBrand.Name} has been edited successfully!",
                    Record = editedBrand
                }));
            }


            return(BadRequest(new OperationResponse <Brand>
            {
                Message = "Something went wrong",
                IsSuccess = false
            }));
        }
        public async Task <IActionResult> Edit(int id)
        {
            var brand = await _repo.GetBrandAsync(id);

            if (brand == null)
            {
                return(NotFound());
            }
            PersianCalendar p     = new PersianCalendar();
            var             model = new BrandViewModel
            {
                Id             = brand.Id,
                Title          = brand.Title,
                Slug           = brand.Slug,
                State          = brand.State.ToString(),
                Creator        = brand.Creator.FirstName + " " + brand.Creator.LastName,
                CreateDate     = p.PersianDate(brand.CreateDate),
                LastModifyDate = brand.LastModifyDate.HasValue ? p.PersianDate(brand.LastModifyDate.Value) : null,
                LastModifier   = brand.LastModifier?.FirstName + " " + brand.LastModifier?.LastName
            };

            ViewBag.Id = id;
            return(View("AddBrand", model));
        }
示例#18
0
 public static BrandViewModel CreateViewModel(this Brand brand)
 {
     var model = new BrandViewModel();
     brand.CopyTo(model);
     return model;
 }
示例#19
0
 public static Brand Create(this BrandViewModel model)
 {
     var brand = new Brand();
     model.CopyTo(brand);
     return brand;
 }
示例#20
0
 public static void CopyTo(this Brand brand, BrandViewModel model)
 {
     model.Id = brand.Id;
     model.Name = brand.Name;
     model.Order = brand.Order;
 }
示例#21
0
        public ActionResult Edit(int Id)
        {
            BrandViewModel BrandViewModel = Mapper.Map <Brand, BrandViewModel>(this._BrandService.GetById(Id));

            return(base.View(BrandViewModel));
        }
示例#22
0
        public ActionResult Edit(FormCollection formCollection, [FetchBrand(KeyName = "id")] BrandEntity entity, BrandViewModel vo)
        {
            if (entity == null || !ModelState.IsValid)
            {
                ModelState.AddModelError("", "参数验证失败.");
                return(View(vo));
            }

            entity.Name        = vo.Name;
            entity.Group       = vo.Group;
            entity.WebSite     = vo.WebSite ?? string.Empty;
            entity.Description = vo.Description ?? string.Empty;
            entity.EnglishName = vo.EnglishName ?? string.Empty;
            entity.UpdatedDate = DateTime.Now;
            entity.UpdatedUser = CurrentUser.CustomerId;
            using (var ts = new TransactionScope())
            {
                if (ControllerContext.HttpContext.Request.Files.Count > 0)
                {
                    var oldImage = _resourceRepository.Get(r => r.SourceType == (int)SourceType.BrandLogo &&
                                                           r.SourceId == entity.Id).FirstOrDefault();
                    if (oldImage != null)
                    {
                        _resourceService.Del(oldImage.Id);
                    }
                    var resources = this._resourceService.Save(ControllerContext.HttpContext.Request.Files
                                                               , CurrentUser.CustomerId
                                                               , -1, entity.Id
                                                               , SourceType.BrandLogo);
                    if (resources != null &&
                        resources.Count() > 0)
                    {
                        entity.Logo = resources[0].AbsoluteUrl;
                    }
                }
                _brandRepository.Update(entity);

                ts.Complete();
            }
            return(RedirectToAction("Details", new { id = entity.Id }));
        }
 private static void CopyToBrand(this BrandViewModel model, Brand brand)
 {
     brand.Name  = model.Name;
     brand.Order = model.Order;
 }
示例#24
0
 public async Task <ResponseViewModel <BrandViewModel> > Delete([FromBody] BrandViewModel BrandObj)
 {
     return(await brandMethod.Delete(BrandObj));
 }
示例#25
0
        public static KeyValuePair<Table, TableViewModel> FieldsTestMap()
        {
            var idTable = Guid.NewGuid();
            var tableName = "Just a table!";
            var countryName = "Cuba";
            var countryId = Guid.NewGuid();

            var table = new Table
            {
                Id = idTable,
                Name = tableName,
                Manufacturer = new Country
                {
                    Id = countryId,
                    Name = countryName
                },
                Sizes = new List<Size>(),
                Brands = new List<Brand>()
            };

            var tableViewModel = new TableViewModel
            {
                Id = idTable,
                Name = tableName,
                Manufacturer = new CountryViewModel
                {
                    Id = countryId,
                    Name = countryName
                },
                Sizes = new List<SizeViewModel>(),
                Brands = new List<BrandViewModel>()
            };

            for (var i = 0; i < 10; i++)
            {
                var brandId = Guid.NewGuid();
                var name = string.Format("Brand {0}", i);
                var brand = new Brand
                {
                    Id = brandId,
                    Name = name,
                };

                var brandViewModel = new BrandViewModel
                {
                    Id = brandId,
                    Name = name,
                };

                table.Brands.Add(brand);
                tableViewModel.Brands.Add(brandViewModel);
            }

            for (var i = 0; i < 5; i++)
            {
                var sizeId = Guid.NewGuid();
                var name = string.Format("Size {0}", i);
                var size = new Size
                {
                    Id = sizeId,
                    Name = name,
                };

                var sizeViewModel = new SizeViewModel
                {
                    Id = sizeId,
                    Name = name,

                };

                table.Sizes.Add(size);
                tableViewModel.Sizes.Add(sizeViewModel);
            }

            return new KeyValuePair<Table, TableViewModel>(table, tableViewModel);
        }
示例#26
0
 public void CreateBrand(BrandViewModel brandViewModel)
 {
     brandAdapter.CreateBrand(brandViewModel);
 }
示例#27
0
 public static void UpdateBrand(this lu_brand brand, BrandViewModel brandVm)
 {
     brand.brand_desc = brandVm.brand_desc;
 }
示例#28
0
        public static KeyValuePair <FashionProduct, FashionProductViewModel> ComplexMap()
        {
            var sizes           = new List <Size>();
            var sizesViewModels = new List <SizeViewModel>();

            var random    = new Random();
            var sizeCount = random.Next(3, 10);
            var cityCount = random.Next(4, 10);

            for (var i = 0; i < sizeCount; i++)
            {
                var newGuid = Guid.NewGuid();
                var name    = string.Format("Size {0}", i);
                var alias   = string.Format("Alias Size {0}", i);
                sizes.Add(
                    new Size
                {
                    Id        = newGuid,
                    Name      = name,
                    Alias     = alias,
                    SortOrder = i
                });
                sizesViewModels.Add(new SizeViewModel
                {
                    Id        = newGuid,
                    Name      = name,
                    Alias     = alias,
                    SortOrder = i
                });
            }

            var cities         = new List <City>();
            var cityViewModels = new List <CityViewModel>();

            var ftRandom = new Random();

            for (var i = 0; i < cityCount; i++)
            {
                var newGuid = Guid.NewGuid();
                var name    = string.Format("City {0}", i);

                var featureCount      = ftRandom.Next(7, 50);
                var features          = new Feature[featureCount];
                var featureViewModels = new List <FeatureViewModel>();

                for (var j = 0; j < featureCount; j++)
                {
                    var fId          = Guid.NewGuid();
                    var fName        = string.Format("Feature - {0}", j);
                    var fDescription = string.Format("Description Feature - {0}", j);
                    features[j] =
                        new Feature
                    {
                        Id          = fId,
                        Name        = fName,
                        Description = fDescription,
                        Rank        = 8
                    };
                    featureViewModels.Add(new FeatureViewModel
                    {
                        Id          = fId,
                        Name        = fName,
                        Description = fDescription,
                        Rank        = 8
                    });
                }

                cities.Add(new City
                {
                    Id       = newGuid,
                    Name     = name,
                    Features = features
                });
                cityViewModels.Add(new CityViewModel
                {
                    Id           = newGuid,
                    Name         = name,
                    FeaturesList = featureViewModels
                });
            }

            var brandId   = Guid.NewGuid();
            var brandName = "Brand name";
            var brand     = new Brand
            {
                Id   = brandId,
                Name = brandName
            };
            var brandViewModel = new BrandViewModel
            {
                Id   = brandId,
                Name = brandName
            };

            var supId         = Guid.NewGuid();
            var supplierName  = "Supplier name";
            var agreementDate = DateTime.Now;
            var supplier      = new Supplier
            {
                Id            = supId,
                Name          = supplierName,
                AgreementDate = agreementDate,
                Rank          = 6,
                Sizes         = sizes,
            };

            var supplierViewModel = new SupplierViewModel
            {
                Id            = supId,
                Name          = supplierName,
                AgreementDate = agreementDate,
                Sizes         = sizesViewModels,
            };

            var sizeId     = Guid.NewGuid();
            var lonelySize = "Lonely size";
            var sizeSAlias = "Size's alias";
            var size       = new Size
            {
                Id        = sizeId,
                Name      = lonelySize,
                Alias     = sizeSAlias,
                SortOrder = 5
            };
            var sizeViewModel = new SizeViewModel
            {
                Id        = sizeId,
                Name      = lonelySize,
                Alias     = sizeSAlias,
                SortOrder = 5
            };

            var optionsCount = random.Next(10, 50);

            var options          = new List <ProductOption>();
            var optionViewModels = new List <ProductOptionViewModel>();

            for (var i = 0; i < optionsCount; i++)
            {
                var optionId = Guid.NewGuid();
                var color    = "Random";
                var discount = 54M;
                var price    = 34M;
                var stock    = 102;
                var weight   = 23;
                options.Add(
                    new ProductOption
                {
                    Id       = optionId,
                    Cities   = cities,
                    Color    = color,
                    Discount = discount,
                    Price    = price,
                    Stock    = stock,
                    Weight   = weight,
                    Size     = size
                });
                optionViewModels.Add(
                    new ProductOptionViewModel
                {
                    Id              = optionId,
                    Cities          = cityViewModels,
                    Color           = color,
                    Discount        = discount,
                    Price           = price,
                    Stock           = stock,
                    Weight          = weight,
                    Size            = sizeViewModel,
                    DiscountedPrice = Math.Floor(price * discount / 100)
                });
            }

            var fpId = Guid.NewGuid();
            var fashionProductDescription = "Fashion product description";
            var ean = "6876876-5345345-345345tgreg-435345df-adskf34";
            var topFashionProductName = "Top Fashion Product";
            var createdOn             = DateTime.Now;
            var end            = DateTime.Now.AddDays(30);
            var start          = DateTime.Now;
            var warehouseOn    = DateTime.Now.AddDays(-3);
            var fashionProduct = new FashionProduct
            {
                Id          = fpId,
                Brand       = brand,
                CreatedOn   = createdOn,
                Description = fashionProductDescription,
                Ean         = ean,
                End         = end,
                Gender      = GenderTypes.Unisex,
                Name        = topFashionProductName,
                Options     = options,
                Start       = start,
                Supplier    = supplier,
                WarehouseOn = warehouseOn
            };

            var fashionProductViewModel = new FashionProductViewModel
            {
                Id             = fpId,
                Brand          = brandViewModel,
                CreatedOn      = createdOn,
                Description    = fashionProductDescription,
                Ean            = ean,
                End            = end,
                OptionalGender = null,
                Name           = topFashionProductName,
                Options        = optionViewModels,
                Start          = start,
                Supplier       = supplierViewModel,
                WarehouseOn    = warehouseOn
            };

            var result = new KeyValuePair <FashionProduct, FashionProductViewModel>(fashionProduct, fashionProductViewModel);

            return(result);
        }
示例#29
0
        public void Update(BrandViewModel blogCategoryVm)
        {
            var blogCategory = Mapper.Map <BrandViewModel, Brand>(blogCategoryVm);

            _brandRepository.Update(blogCategory);
        }
示例#30
0
 public static void CopyTo(this BrandViewModel Model, Brand brand)
 {
     brand.Name  = Model.Name;
     brand.Order = Model.Order;
 }
示例#31
0
        public static KeyValuePair<FashionProduct, FashionProductViewModel> ComplexMap()
        {
            var sizes = new List<Size>();
            var sizesViewModels = new List<SizeViewModel>();

            var random = new Random();
            var sizeCount = random.Next(3, 10);
            var cityCount = random.Next(4, 10);

            for (var i = 0; i < sizeCount; i++)
            {
                var newGuid = Guid.NewGuid();
                var name = string.Format("Size {0}", i);
                var alias = string.Format("Alias Size {0}", i);
                sizes.Add(
                    new Size
                    {
                        Id = newGuid,
                        Name = name,
                        Alias = alias,
                        SortOrder = i
                    });
                sizesViewModels.Add(new SizeViewModel
                {
                    Id = newGuid,
                    Name = name,
                    Alias = alias,
                    SortOrder = i
                });
            }

            var cities = new List<City>();
            var cityViewModels = new List<CityViewModel>();

            var ftRandom = new Random();
            for (var i = 0; i < cityCount; i++)
            {
                var newGuid = Guid.NewGuid();
                var name = string.Format("City {0}", i);

                var featureCount = ftRandom.Next(7 , 50);
                var features = new Feature[featureCount];
                var featureViewModels = new List<FeatureViewModel>();

                for (var j = 0; j < featureCount; j++)
                {
                    var fId = Guid.NewGuid();
                    var fName = string.Format("Feature - {0}", j);
                    var fDescription = string.Format("Description Feature - {0}", j);
                    features[j] =
                        new Feature
                        {
                            Id = fId,
                            Name = fName,
                            Description = fDescription,
                            Rank = 8
                        };
                    featureViewModels.Add(new FeatureViewModel
                    {
                        Id = fId,
                        Name = fName,
                        Description = fDescription,
                        Rank = 8
                    });
                }

                cities.Add(new City
                {
                    Id = newGuid,
                    Name = name,
                    Features = features
                });
                cityViewModels.Add(new CityViewModel
                {
                    Id = newGuid,
                    Name = name,
                    FeaturesList = featureViewModels
                });
            }

            var brandId = Guid.NewGuid();
            var brandName = "Brand name";
            var brand = new Brand
            {
                Id = brandId,
                Name = brandName
            };
            var brandViewModel = new BrandViewModel
            {
                Id = brandId,
                Name = brandName
            };

            var supId = Guid.NewGuid();
            var supplierName = "Supplier name";
            var agreementDate = DateTime.Now;
            var supplier = new Supplier
            {
                Id = supId,
                Name = supplierName,
                AgreementDate = agreementDate,
                Rank = 6,
                Sizes = sizes,
            };

            var supplierViewModel = new SupplierViewModel
            {
                Id = supId,
                Name = supplierName,
                AgreementDate = agreementDate,
                Sizes = sizesViewModels,
            };

            var sizeId = Guid.NewGuid();
            var lonelySize = "Lonely size";
            var sizeSAlias = "Size's alias";
            var size = new Size
            {
                Id = sizeId,
                Name = lonelySize,
                Alias = sizeSAlias,
                SortOrder = 5
            };
            var sizeViewModel = new SizeViewModel
            {
                Id = sizeId,
                Name = lonelySize,
                Alias = sizeSAlias,
                SortOrder = 5
            };

            var optionsCount = random.Next(10, 50);

            var options = new List<ProductOption>();
            var optionViewModels = new List<ProductOptionViewModel>();

            for (var i = 0; i < optionsCount; i++)
            {
                var optionId = Guid.NewGuid();
                var color = "Random";
                var discount = 54M;
                var price = 34M;
                var stock = 102;
                var weight = 23;
                options.Add(
                    new ProductOption
                    {
                        Id = optionId,
                        Cities = cities,
                        Color = color,
                        Discount = discount,
                        Price = price,
                        Stock = stock,
                        Weight = weight,
                        Size = size
                    });
                optionViewModels.Add(
                    new ProductOptionViewModel
                    {
                        Id = optionId,
                        Cities = cityViewModels,
                        Color = color,
                        Discount = discount,
                        Price = price,
                        Stock = stock,
                        Weight = weight,
                        Size = sizeViewModel,
                        DiscountedPrice = Math.Floor(price * discount / 100)
                    });
            }

            var fpId = Guid.NewGuid();
            var fashionProductDescription = "Fashion product description";
            var ean = "6876876-5345345-345345tgreg-435345df-adskf34";
            var topFashionProductName = "Top Fashion Product";
            var createdOn = DateTime.Now;
            var end = DateTime.Now.AddDays(30);
            var start = DateTime.Now;
            var warehouseOn = DateTime.Now.AddDays(-3);
            var fashionProduct = new FashionProduct
            {
                Id = fpId,
                Brand = brand,
                CreatedOn = createdOn,
                Description = fashionProductDescription,
                Ean = ean,
                End = end,
                Gender = GenderTypes.Unisex,
                Name = topFashionProductName,
                Options = options,
                Start = start,
                Supplier = supplier,
                WarehouseOn = warehouseOn
            };

            var fashionProductViewModel = new FashionProductViewModel
            {
                Id = fpId,
                Brand = brandViewModel,
                CreatedOn = createdOn,
                Description = fashionProductDescription,
                Ean = ean,
                End = end,
                OptionalGender = null,
                Name = topFashionProductName,
                Options = optionViewModels,
                Start = start,
                Supplier = supplierViewModel,
                WarehouseOn = warehouseOn
            };

            var result = new KeyValuePair<FashionProduct, FashionProductViewModel>(fashionProduct, fashionProductViewModel);
            return result;
        }
示例#32
0
        public async Task <IActionResult> DeleteBrand(BrandViewModel viewModel)
        {
            var data = await _repository.DeleteBrand(viewModel);

            return(RedirectToAction("Index", new RouteValueDictionary(new { status = data })));
        }
示例#33
0
        public IActionResult Index()
        {
            var model = new BrandViewModel();

            return(View(model));
        }
示例#34
0
 public GenericResult Add(AnnouncementViewModel announcementViewModel, List <AnnouncementUserViewModel> announcementUsers, BrandViewModel brandViewModel)
 {
     try
     {
         _brandRepository.Add(_mapper.Map <BrandViewModel, Brand>(brandViewModel));
         // Real Time
         var announcement = _mapper.Map <AnnouncementViewModel, Announcement>(announcementViewModel);
         _announceRepository.Add(announcement);
         foreach (var announcementUserViewModel in announcementUsers)
         {
             _announceUserRepository.Add(_mapper.Map <AnnouncementUserViewModel, AnnouncementUser>(announcementUserViewModel));
         }
         return(new GenericResult(true, "Add Successful", "Successful"));
     }
     catch (Exception)
     {
         return(new GenericResult(false, "Add Failed", "Error"));
     }
 }
示例#35
0
        public string GetCars(string treeNodeName, int color, int volEngine, int colsNum,
                              string minPrice, string maxPrice, string dateTime)
        {
            decimal min = decimal.Parse(minPrice);
            decimal max = decimal.Parse(maxPrice);

            var      searchDate = dateTime.Split('/');
            DateTime date       = new DateTime(Convert.ToInt32(searchDate[0]), Convert.ToInt32(searchDate[1]), Convert.ToInt32(searchDate[2]));

            if (treeNodeName == "ALL")
            {
                cars = Mapper.Map <IEnumerable <CarDTO>, List <CarViewModel> >(carService.GetAllCars());
            }
            else
            {
                BrandViewModel brand = Mapper.Map <BrandDTO, BrandViewModel>(brandService.GetAllBrands().FirstOrDefault(x => x.Name == treeNodeName));
                if (brand != null)
                {
                    cars = Mapper.Map <IEnumerable <CarDTO>, List <CarViewModel> >(carService.GetAllCars().Where(x => x.BrandId == brand.Id));
                }
                else
                {
                    ModelViewModel model = Mapper.Map <ModelDTO, ModelViewModel>(modelService.GetAllModels().FirstOrDefault(x => x.Name == treeNodeName));
                    if (model != null)
                    {
                        cars = Mapper.Map <IEnumerable <CarDTO>, List <CarViewModel> >(carService.GetAllCars().Where(x => x.BrandId == model.BrandId && x.ModelId == model.Id));
                    }
                }
            }

            if (color - 1 >= 0)
            {
                cars = cars.FindAll(x => x.Color == (Auxiliary.COLOR)(color - 1));
            }

            if (volEngine - 1 >= 0)
            {
                cars = cars.FindAll(x => x.VolumeEngine == Auxiliary.VolumeEngine[volEngine - 1]);
            }
            List <CarTileModel> tiles = new List <CarTileModel>();

            foreach (var item in cars)
            {
                var time = item.Prices.Where(x => DateTime.Compare(x.Date, date) < 0).ToList();

                if (time.Count == 0)
                {
                    continue;
                }

                var price = time.OrderByDescending(x => x.Date).First();

                if (price.Price < min || price.Price > max)
                {
                    continue;
                }

                CarTileModel model = new CarTileModel()
                {
                    PhotoUrl     = item.Model.PhotoUrl,
                    Photo        = item.Brand.Photo,
                    Name         = item.Model.Name,
                    Color        = item.Color,
                    VolumeEngine = item.VolumeEngine,
                    Description  = item.Description
                    ,
                    Date  = price.Date,
                    Price = price.Price
                };

                tiles.Add(model);
            }

            return(CarCatalog.Helpers.CarsListHelper.CreateCarsList(tiles, colsNum).ToString());
        }