예제 #1
0
        private static void AddInfo(CustomersProductsDBContext dbContext)
        {
            var customersCount = rand.Next(0, 20);

            for (int i = 0; i <= customersCount; i++)
            {
                var customer = new Customer
                {
                    FirstName   = "FirstName #" + i,
                    LastName    = "LastName #" + i,
                    PhoneNumber = rand.Next(1000000, 9000000).ToString()
                };

                var productsCount = rand.Next(10, 30);

                for (int y = 0; y <= productsCount; y++)
                {
                    var customerProduct = new CustomersProducts
                    {
                        Product = new Product
                        {
                            Name  = "First Test Product #" + y,
                            Price = rand.Next(50, 200)
                        },
                        Customer = customer,
                        Qty      = rand.Next(0, 100)
                    };
                    dbContext.CustomersProducts.Add(customerProduct);
                }
            }
            dbContext.SaveChanges();
        }
예제 #2
0
        public ActionResult Recording()
        {
            CustomersProducts model = serviceManager.GetCPViewModel();

            ViewBag.MessageSuccess = TempData[SAVE_SUCCESS_KEY];
            ViewBag.MessageFail    = TempData[SAVE_FAILED_KEY];
            return(View(model));
        }
        public CustomersProducts GetCPViewModel()
        {
            List <Product>    products  = productService.All();
            List <User>       customers = userService.GetCustomers();
            CustomersProducts viewModel = new CustomersProducts {
                products = products, customers = customers
            };

            return(viewModel);
        }
예제 #4
0
        public async Task <TaskResult <CustomersProductsDto> > SaveAsync(CustomersProductsDto customersProductsDto)
        {
            var costumer = new CustomersProducts {
                Active = customersProductsDto.Active, CreatedAt = customersProductsDto.CreatedAt, ApplicationUserId = customersProductsDto.ApplicationUserId, ProductsId = customersProductsDto.ProductsId, Id = customersProductsDto.Id, UpdatedAt = customersProductsDto.UpdatedAt
            };
            var result = new TaskResult <CustomersProductsDto>();

            try
            {
                _context.CustomersProducts.Add(costumer);
                await _context.SaveChangesAsync();

                result.Message = $"Se agregó el producto al cliente de forma exitosa!";
            }
            catch (Exception e)
            {
                result.Success = false;
                result.Message = $"Error al intentar agregar el producto: {e.Message}";
            }
            return(result);
        }
예제 #5
0
        public async Task <TaskResult <CustomersProductsDto> > UpdateAsync(CustomersProductsDto customersProductsDto)
        {
            var costumer = new CustomersProducts {
                Active = customersProductsDto.Active, CreatedAt = customersProductsDto.CreatedAt, Id = customersProductsDto.Id, UpdatedAt = customersProductsDto.UpdatedAt
            };
            var result = new TaskResult <CustomersProductsDto>();

            try
            {
                _context.CustomersProducts.Add(costumer);
                _context.Entry(costumer).State = System.Data.Entity.EntityState.Modified;
                await _context.SaveChangesAsync();

                result.Data    = customersProductsDto;
                result.Message = "El registro fue actualizado correctamente";
            }
            catch (Exception e)
            {
                result.Success = false;
                result.Message = $"Error al intentar actualizar información del cliente: {e.Message}";
            }
            return(result);
        }