Ejemplo n.º 1
0
        public ActionResult Action(tblTypeProduct objSubmit)
        {
            if (objSubmit.ID == 0)
            {
                objSubmit.DateCreated = DateTime.Now;
                objSubmit.DateUpdated = DateTime.Now;
                objSubmit.IsDeleted   = false;
                objSubmit.IsShow      = true;
                productTypeRepository.Add(objSubmit);
            }
            else
            {
                var obj = productTypeRepository.GetById <tblTypeProduct>(objSubmit.ID);

                UpdateModel(obj);

                objSubmit.DateUpdated = DateTime.Now;

                productTypeRepository.Update(obj);
            }

            productTypeGroupMapRepository.ResetGroupOfType(objSubmit.ID, Web365Utility.Web365Utility.StringToArrayInt(Request["groupID"]));

            productTypeRepository.ResetListPicture(objSubmit.ID, Request["listPictureId"]);

            return(Json(new
            {
                Error = false
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        private void OnAddExecute()
        {
            var wrapper = new ProductTypeWrapper(new ProductType());

            wrapper.PropertyChanged += Wrapper_PropertyChanged;
            _productTypeRepository.Add(wrapper.Model);
            ProductTypes.Add(wrapper);

            // Triiger the validation
            wrapper.Type = "";
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Description,Name,CustomerId,PriceCalculationType")] ProductType productType)
        {
            if (ModelState.IsValid)
            {
                var customerId = await _customerIdService.GetCustomerId();

                productType.CustomerId = customerId;

                await _productTypeRepository.Add(productType);

                return(RedirectToAction("Index"));
            }

            return(View(productType));
        }
Ejemplo n.º 4
0
        public ActionResult ProductTypeInsert(ProductTypeViewModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("productType");
            }

            var productTypeModel = new ProductType()
            {
                Title = model.Title,
                Show  = model.Show
            };

            _productTypeRepository.Add(productTypeModel);
            _productTypeRepository.Complete();

            return(Json(""));
        }
        public ActionResult Create(ProductTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _productTypeRepository.Add(new ProductType()
                    {
                        Id       = Guid.NewGuid().ToString(),
                        TypeName = model.TypeName
                    });
                    _productTypeRepository.Save(requestContext);

                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    return(View());
                }
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> AddProductType([FromBody] ProductTypeSaveResource saveResource)
        {
            if (!_auth.IsAppAdmin(User))
            {
                return(NoContent());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /* Pre-existence Test */
            var filter = new MdaProductTypeQuery()
            {
                Name = saveResource.Name
            };
            var productTypeFromRepo = await _repo.GetProductTypes(filter);

            if (productTypeFromRepo.Any())
            {
                return(BadRequest($"Product Type {saveResource.Name} already exists."));
            }

            var productType = _mapper.Map <MdaProductType>(saveResource);

            productType.CreatedBy = User.Identity.Name;

            _repo.Add(productType);

            if (await _repo.SaveAll())
            {
                return(Ok(productType));
            }

            return(BadRequest("Failed to add product type."));
        }
Ejemplo n.º 7
0
        public ActionResult Create(ProductTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _productTypeRepository.Add(new ProductType()
                    {
                        Id          = Guid.NewGuid().ToString(),
                        TypeName    = model.TypeName,
                        Description = model.Description,
                        SeoAlias    = TextHelper.ToUnsignString(model.TypeName)
                    });
                    _productTypeRepository.Save(RequestContext);

                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    return(View());
                }
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        // public FormFile ConvertToForm(string FilePath)
        // {

        //     //using (var stream = File.OpenRead(@FilePath))
        //  //{
        //      var stream = File.OpenRead(@FilePath);
        //         FormFile file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
        //         {
        //             Headers = new HeaderDictionary(),
        //             ContentType = FilePath.GetContentType()
        //         };
        //      stream.Position =0;
        //      return file;
        //     //}

        // }

        public async Task SeedAsync()
        {
            try
            {
                var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                if (await _productBrandRepo.CountAsync() == 0)
                {
                    var brandsData =
                        File.ReadAllText(path + @"/SeedData/brands.json");

                    var brands = JsonSerializer.Deserialize <List <ProductBrand> >(brandsData);

                    foreach (var item in brands)
                    {
                        await _productBrandRepo.Add(item);
                    }
                }

                if (await _productTypeRepo.CountAsync() == 0)
                {
                    var typesData =
                        File.ReadAllText(path + @"/SeedData/types.json");

                    var types = JsonSerializer.Deserialize <List <ProductType> >(typesData);

                    foreach (var item in types)
                    {
                        await _productTypeRepo.Add(item);
                    }
                }
                await SeedProducts();

                if (await _productRepo.CountAsync() == 0)
                {
                    var productsData =
                        File.ReadAllText(path + @"/SeedData/products1.json");

                    var products = JsonSerializer.Deserialize <List <ProductSeed> >(productsData);

                    foreach (var item in products)
                    {
                        var images = new List <ObjectId>();
                        foreach (var url in item.PictureUrls)
                        {
                            var image = new Image
                            {
                                // ProductId = createdProduct.Id,
                                ImageContent = File.ReadAllBytes(path + url)
                            };
                            // var byteFile = File.ReadAllBytes(path + url);
                            await _imageRepo.Upload(image);

                            images.Add(image.Id);
                        }
                        var product = new Product
                        {
                            Name         = item.Name,
                            Description  = item.Description,
                            Price        = item.Price,
                            ProductBrand = await _productBrandRepo.GetByName("NetCore"),
                            ProductType  = await _productTypeRepo.GetByName("Hats"),
                            //  ProductType = item.ProductType,
                            //  ProductBrand = item.ProductBrand,
                            ImageIds = images
                        };
                        var createdProduct = await _productRepo.Add(product);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
        }
Ejemplo n.º 9
0
 public ProductType Add(ProductType productType)
 {
     return(_productTypeRepository.Add(productType));
 }
Ejemplo n.º 10
0
        public async Task <ActionResult <Product> > Post([FromBody] ProductType productType)
        {
            await _productTypeRepository.Add(productType);

            return(Ok(productType));
        }
Ejemplo n.º 11
0
 public void Create(ProductTypeViewModel model)
 {
     var entity = mapper.Map(model, new ProductType());
     productTypeRepository.Add(entity);
     productTypeRepository.SaveChanges();
 }
Ejemplo n.º 12
0
 public Response <ProductType> Add(ProductType item, string user)
 {
     return(_productTypeRepositoryDAC.Add(item, user));
 }
Ejemplo n.º 13
0
        public void AddProductType(ProductTypeDTO productTypeDTO)
        {
            var productType = productTypeDTO.MappingProductType();

            productTypeRepository.Add(productType);
        }
Ejemplo n.º 14
0
 public void Add(ProductType productType)
 {
     repository.Add(productType);
 }