Exemplo n.º 1
0
        public async Task AddOrderIncome(CreateViewModel orderModel)
        {
            // we create the date with the current date
            var dateOrderIncome = DateTime.Now;

            OrderIncome order = new OrderIncome
            {
                IdProvider = orderModel.IdProvider,
                IdUser     = orderModel.IdUser,
                Total      = orderModel.Total,
                State      = "Accept"
            };

            _context.OrderIncomes.Add(order);
            await _context.SaveChangesAsync();

            // Adding details to detailOrder
            var IdOrderIncome = order.IdOrderIncome;

            // We loop de property details in CreateViewModel to add every
            // detail in OrderDetail Table in the same method Add of OrderIncome
            foreach (var det in orderModel.Details)
            {
                OrderIncomeDetails detail = new OrderIncomeDetails
                {
                    IdOrderIncome = IdOrderIncome,
                    IdProduct     = det.IdProduct,
                    Amount        = det.Amount,
                    DueDate       = det.DueDate,
                    UnitCost      = det.UnitCost
                };
                _context.OrderIncomeDetails.Add(detail);
            }
            await _context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task AddLoss(CreateViewModel lossModel)
        {
            Losses losses = new Losses
            {
                Cause = lossModel.Cause,
                State = lossModel.State
            };

            _context.Losses.Add(losses);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task AddLaboratory(CreateViewModel model)
        {
            Laboratory lab = new Laboratory
            {
                LaboratoryName = model.LaboratoryName,
                Description    = model.Description,
                Condition      = model.Condition
            };

            _context.Laboratories.Add(lab);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task AddRole(CreateViewModel model)
        {
            var role = new Role
            {
                RoleName    = model.RoleName,
                Description = model.Description,
                Condition   = model.State
            };

            await _context.Roles.AddAsync(role);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 5
0
        public async Task AddAsync(CreateViewModel model)
        {
            Category category = new Category
            {
                Name        = model.Name,
                Description = model.Description,
                Condition   = model.Condition
            };

            _context.Categories.Add(category);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 6
0
        public async Task AddDelivery(CreateViewModel deliveryModel)
        {
            Delivery delivery = new Delivery
            {
                IdSale   = deliveryModel.IdSale,
                IdClient = deliveryModel.IdClient,
                Adress   = deliveryModel.Adress,
                State    = deliveryModel.State
            };

            _context.Deliveries.Add(delivery);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public async Task AddProvider(CreateViewModel providerModel)
        {
            Provider provider = new Provider
            {
                ProviderName   = providerModel.ProviderName,
                DocumentNumber = providerModel.DocumentNumber,
                Address        = providerModel.Address,
                PhoneNumber    = providerModel.PhoneNumber,
                Email          = providerModel.Email
            };

            _context.Providers.Add(provider);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 8
0
        public async Task AddClient(CreateViewModel clientModel)
        {
            Client client = new Client
            {
                Name           = clientModel.Name,
                LastName       = clientModel.LastName,
                DocumentType   = clientModel.DocumentType,
                DocumentNumber = clientModel.DocumentNumber,
                PhoneNumber    = clientModel.PhoneNumber,
                Condition      = clientModel.Condition,
            };

            _context.Clients.Add(client);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 9
0
        public async Task AddAsync(CreateViewModel model)
        {
            //Product product = new Product
            //{
            //    IdCategory = model.IdCategory,
            //    IdLaboratory = model.IdLaboratory,
            //    ProductName = model.ProductName,
            //    BarCode = model.BarCode,
            //    Indicative = model.Indicative,
            //    Stock = model.Stock,
            //    UnitPrice = model.UnitPrice,
            //    SalePrice = model.SalePrice,
            //    Condition = model.Condition
            //};

            Product product = _mapper.Map <Product>(model);

            await _context.Products.AddAsync(product);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 10
0
        public async Task AddSale(CreateViewModel saleModel)
        {
            // we create the date with the current date
            var dateOrderIncome = DateTime.Now;

            Sale sale = new Sale
            {
                IdUser        = saleModel.IdUser,
                IdClient      = saleModel.IdClient,
                TypeSale      = saleModel.TypeSale,
                VoucherSeries = saleModel.VoucherSeries,
                VoucherNumber = saleModel.VoucherNumber,
                TotalPrice    = saleModel.TotalPrice,
                State         = "Accepted"
            };

            _context.Sales.Add(sale);

            await _context.SaveChangesAsync();

            // Addind Details to DetailSale
            var id = sale.IdSale;

            // We loop de property details in CreateViewModel to add every
            // detail in SaleDetail Table in the same method Add of Sale
            foreach (var det in saleModel.Details)
            {
                SaleDetail detail = new SaleDetail
                {
                    IdSale    = id,
                    IdProduct = det.IdProduct,
                    Amount    = det.Amount,
                    Discount  = det.Discount,
                    UnitPrice = det.UnitPrice,
                    SalePrice = det.SalePrice
                };
                _context.saleDetails.Add(detail);
            }
            await _context.SaveChangesAsync();
        }
Exemplo n.º 11
0
        public async Task UpdateUser(UpdateViewModel UserModel)
        {
            var user = await _context.Users.FirstOrDefaultAsync(u => u.IdUser == UserModel.IdUser);

            user.IdUser         = UserModel.IdUser;
            user.IdRole         = UserModel.IdRole;
            user.UserName       = UserModel.UserName;
            user.DocumentType   = UserModel.DocumentType;
            user.DocumentNumber = UserModel.DocumentNumber;
            user.Address        = UserModel.Address;
            user.PhoneNumber    = UserModel.PhoneNumber;
            user.Email          = UserModel.Email;

            if (UserModel.Act_Password == true)
            {
                CreatePassword(UserModel.Password, out byte[] passwordHash, out byte[] passwordSalt);
                user.PasswordHash = passwordHash;
                user.PasswordSalt = passwordSalt;
            }

            await _context.SaveChangesAsync();
        }