public async Task <bool> PutEmployee(Employee employee)
        {
            var oldemp = _context.Employees.Where(e => e.EmployeeId == employee.EmployeeId).FirstOrDefault();

            if (oldemp != null)
            {
                try
                {
                    _context.Employees.Remove(oldemp);

                    _context.SaveChanges();

                    _context.Employees.Add(employee);


                    if (employee.EmployeeUser != null)
                    {
                        _context.Users.Attach(employee.EmployeeUser);
                    }

                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }


                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> PutOrderProduct(Guid id, OrderProduct orderProduct)
        {
            var product = _context.OrderProducts.Where(o => o.OrderProductId == orderProduct.OrderProductId).FirstOrDefault();

            if (product != null)
            {
                _context.OrderProducts.Remove(product);

                _context.SaveChanges();

                _context.OrderProducts.Add(orderProduct);

                _context.SaveChanges();

                return(true);
            }
            else
            {
                return(false);
            }

            //if (id != orderProduct.OrderProductId)
            //{
            //    return BadRequest();
            //}

            //_context.Entry(orderProduct).State = EntityState.Modified;

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

            //return NoContent();
        }
        public async Task <bool> PutProduct(Product product)
        {
            var oldproducts = _context.Products.Where(p => p.ProductId == product.ProductId).FirstOrDefault();

            if (oldproducts != null)
            {
                _context.Products.Remove(oldproducts);

                _context.SaveChanges();

                _context.Products.Add(product);

                _context.SaveChanges();

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <bool> PutUserRequest(UserRequest userRequest)
        {
            var request = _context.Requests.Where(r => r.RequestId == userRequest.RequestId).FirstOrDefault();

            if (request != null)
            {
                _context.Requests.Remove(request);

                _context.Requests.Add(userRequest);

                _context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        public async Task <User> PutUser(User user)
        {
            var oldUser = _context.Users.Where(u => u.UserId == user.UserId).FirstOrDefault();

            if (oldUser != null)
            {
                _context.Users.Remove(oldUser);

                _context.Users.Add(user);
                _context.Attach(user.UserLogin);

                if (user.Stores.Count > 0)
                {
                    foreach (var item in user.Stores)
                    {
                        _context.Attach(item);
                    }
                }


                try
                {
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                return(user);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <bool> > ModifyOldConnections(UsersConnected usersConnected)
        {
            var userconnections = await _context.usersConnecteds.Where(usc => usc.UserID == usersConnected.UserID && usc.IsDisable == false).ToListAsync();


            if (userconnections.Count() > 0)
            {
                foreach (var item in userconnections)
                {
                    item.IsDisable = true;

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

                    _context.SaveChanges();
                }


                return(true);
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 7
0
        public async Task <bool> PutOrder(Order order)
        {
            var oldOrder = _context.Orders.Where(o => o.OrderId == order.OrderId).FirstOrDefault();



            if (oldOrder != null)
            {
                try
                {
                    _context.Orders.Remove(oldOrder);

                    _context.SaveChanges();

                    _context.Add(order);

                    //order.StoreOrder= null;

                    if (order.StoreOrder != null)
                    {
                        _context.Attach(order.StoreOrder);

                        if (order.StoreOrder.Products != null)
                        {
                            foreach (var item in order.StoreOrder.Products)
                            {
                                _context.Attach(item);
                            }
                        }


                        order.StoreOrder.WorkHours = null;

                        if (order.StoreOrder.WorkHours != null)
                        {
                            foreach (var item in order.StoreOrder.WorkHours)
                            {
                                _context.Attach(item);
                            }
                        }
                    }

                    ProductController productController = new ProductController(_context);
                    if (order.OrderStatus == Status.Submited)
                    {
                        foreach (var item in order.OrderProducts)
                        {
                            var product = _context.Products.Where(p => p.StoreId == item.StoreId && p.ProductName == item.ProductName).FirstOrDefault();

                            if (product != null && product.InventoryQuantity > 0)
                            {
                                var result = productController.UpdateInventoryFromOrderSubmited(product.ProductId, item.Quantity);
                            }
                        }
                    }



                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }


                return(true);
            }
            else
            {
                return(false);
            }
        }