public async Task <IActionResult> PutMunicipality([FromRoute] int id, [FromBody] Municipality municipality)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != municipality.Id)
            {
                return(BadRequest());
            }

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

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

            return(Ok(_context.Municipalities.Find(id)));
        }
        public async Task <IActionResult> PutMotive([FromRoute] int id, [FromBody] Motive motive)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != motive.Id)
            {
                return(BadRequest());
            }

            motive.UpdatedAt = DateTimeOffset.Now;

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

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

            return(Ok(_context.Motives.Find(id)));
        }
        public async Task <IActionResult> PutDepartment([FromRoute] int id, [FromBody] Department department)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != department.Id)
            {
                return(BadRequest());
            }

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

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

            return(Ok(_context.Departments.Find(id)));
        }
        public async Task <IActionResult> PutExchangeRateByCustomer([FromRoute] int id, [FromBody] ExchangeRateByCustomer exchangeRateByCustomer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != exchangeRateByCustomer.Id)
            {
                return(BadRequest());
            }

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

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

            return(Ok(_context.ExchangeRateByCustomers.Find(id)));
        }
Example #5
0
        public async Task <IActionResult> PutInventoryLiquidation([FromRoute] int id, [FromBody] InventoryLiquidation inventoryLiquidation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != inventoryLiquidation.Id)
            {
                return(BadRequest());
            }

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

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

            return(Ok(_context.InventoryLiquidations.Find(id)));
        }
        public async Task <IActionResult> PutCostCenterByItemFamily([FromRoute] int id, [FromBody] CostCenterByItemFamily costCenterByItemFamily)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != costCenterByItemFamily.Id)
            {
                return(BadRequest());
            }

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

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

            return(Ok(_context.CostCenterByItemFamilies.Find(id)));
        }
        public async Task <IActionResult> PutTargetSale([FromRoute] int id, [FromBody] TargetSale targetSale)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != targetSale.Id)
            {
                return(BadRequest());
            }

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

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

            return(Ok(_context.TargetSales.Find(id)));
        }
Example #8
0
        public async Task <IActionResult> PutAuthorizationCodeType([FromRoute] int id, [FromBody] AuthorizationCodeType authorizationCodeType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != authorizationCodeType.Id)
            {
                return(BadRequest());
            }

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

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

            return(Ok(_context.AuthorizationCodeTypes.Find(id)));
        }
Example #9
0
        public async Task <IActionResult> PutBonusStatusLog([FromRoute] int id, [FromBody] BonusStatusLog bonusStatusLog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bonusStatusLog.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #10
0
        public async Task <IActionResult> PutSynchronizationStep([FromRoute] int id, [FromBody] SynchronizationStep synchronizationStep)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != synchronizationStep.Id)
            {
                return(BadRequest());
            }

            synchronizationStep.UpdatedAt = DateTimeOffset.Now;

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

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

            return(Ok(_context.SynchronizationSteps.Find(id)));
        }
        public async Task <IActionResult> PostDispatch([FromRoute] int pickingId, [FromBody] List <string> orderNumbers)
        {
            if (orderNumbers.Any())
            {
                // Get list of orders by order numbers
                List <Models.Order> orders = await _context
                                             .Orders
                                             .Where(x => orderNumbers.Contains(x.OrderNumber))
                                             .Where(x => x.ConsolidatedOrderId == null)
                                             .ToListAsync();

                // Verify whether any order was found by order number
                if (orders.Any())
                {
                    // Get current date/time
                    DateTimeOffset now = DateTimeOffset.Now;

                    // Create new empty consolidated order object
                    ConsolidatedOrder consolidatedOrder = new ConsolidatedOrder();
                    consolidatedOrder.RouteCode   = orders.First().DeliveryRoute;
                    consolidatedOrder.PickingId   = pickingId;
                    consolidatedOrder.OrderStatus = 0; // Assigned
                    consolidatedOrder.CreatedAt   = now;
                    consolidatedOrder.UpdatedAt   = now;

                    // Add consolidated order to database context
                    _context.ConsolidatedOrders.Add(consolidatedOrder);

                    // Save new consolidated order
                    await _context.SaveChangesAsync();

                    // Iterate through all orders found
                    foreach (var order in orders)
                    {
                        // Assign consolidated order id to order
                        order.ConsolidatedOrderId = consolidatedOrder.Id;

                        // Add modify status to entity
                        _context.Entry(order).State = EntityState.Modified;

                        // Save changes
                        await _context.SaveChangesAsync();
                    }

                    // Return new consolidated order created
                    return(Ok(consolidatedOrder));
                }
                else
                {
                    return(NotFound(new { error = "Non order found into the list of order number given" }));
                }
            }
            else
            {
                return(BadRequest(new { error = "Order numbers can not be empty" }));
            }
        }
        public async Task <IActionResult> PostApplicationSetting([FromBody] ApplicationSetting applicationSetting)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var now = DateTimeOffset.Now;

            applicationSetting.Status = Status.Active;

            applicationSetting.CreatedAt = now;
            applicationSetting.UpdatedAt = now;

            _context.ApplicationSettings.Add(applicationSetting);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetApplicationSetting", new { id = applicationSetting.Id }, applicationSetting));
        }
Example #13
0
        public void LoadInventoryForToday(string route, List <InitialInventoryLoadWithLot> initialInventoryLoadWithLots)
        {
            // Create new initial inventory header
            Models.InitialInventory initialInventory = new Models.InitialInventory
            {
                Route = route,
                SynchronizationDate = DateTime.Now,
                SynchronizationId   = CreateSynchronizationRecord(route, initialInventoryLoadWithLots.Count())
            };

            // Add new initial inventory to database context
            _context.InitialInventories.Add(initialInventory);

            // Save initial inventory to database
            _context.SaveChangesAsync();

            // Create initial inventory items
            CreateInitialInventoryItems(initialInventory, initialInventoryLoadWithLots);
        }
Example #14
0
        public async Task <IActionResult> PutDevice([FromRoute] int id, [FromBody] Device device)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != device.Id)
            {
                return(BadRequest());
            }

            var _device = await _context.Devices.FindAsync(id);

            device.Status    = _device.Status;
            device.CreatedAt = _device.CreatedAt;
            device.UpdatedAt = DateTimeOffset.Now;

            _context.Entry(_device).State = EntityState.Detached;

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

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

            return(Ok(_context.Devices.Find(id)));
        }
        public async Task <IActionResult> AcceptInvitation([FromBody] Models.User _user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var users = await _context
                        .Users
                        .Include(x => x.Info)
                        .ThenInclude(x => x.Phones)
                        .Include(x => x.Setting)
                        .Include(x => x.Roles)
                        .ThenInclude(x => x.Role)
                        .ThenInclude(x => x.Modules)
                        .ThenInclude(x => x.Module)
                        .ThenInclude(x => x.Children)
                        .Include(x => x.Devices)
                        .ThenInclude(x => x.Device)
                        .Where(x => x.Username == _user.Username)
                        .ToListAsync();

            if (users.Any())
            {
                if (string.IsNullOrEmpty(_user.TypedPassword))
                {
                    return(StatusCode(403, "Password can not be empty"));
                }

                var user = users.First();

                Helpers.User.CreatePassword(_user.TypedPassword, out byte[] hashPasswordSalt, out byte[] hashPassword);

                user.PasswordSalt           = hashPasswordSalt;
                user.Password               = hashPassword;
                user.ResetPasswordToken     = null;
                user.ResetPasswordSentAt    = DateTimeOffset.MinValue;
                user.ResetPasswordExpiredAt = DateTimeOffset.MinValue;
                user.Status    = Status.Active;
                user.UpdatedAt = DateTimeOffset.Now;

                // Update user setting with last consecutive invoices
                UpdateUserSettingWithLastConsecutiveNumbers(user);

                // Update user roles with their synchronization steps
                UpdateUserRolesWithSynchronizationSteps(user);

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

                try
                {
                    await _context.SaveChangesAsync();

                    return(CreatedAtAction("GetUser", new { username = user.Username }, user));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                return(NotFound("Username can not be found"));
            }
        }