Exemplo n.º 1
0
        public async Task Remove(T item)
        {
            dbContext.Set <T>().Remove(item);
            await dbContext.SaveChangesAsync();

            await OnDbChanged();
        }
Exemplo n.º 2
0
        public async Task <bool> ApplyOrder()
        {
            await dbContext.Tours.LoadAsync();

            _currentOrder.TourId = _tourId;

            if (!IsEdit)
            {
                _currentOrder.CreationDate = DateTimeOffset.Now;
                _currentOrder.OrderStatus  = OrderStatus.Active;
                _currentOrder.ClientId     = _clientId;
                dbContext.Orders.Add(_currentOrder);
            }
            else
            {
                dbContext.Entry(_currentOrder).State = EntityState.Modified;
            }

            try
            {
                await dbContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public async Task <bool> ApplyOrder()
        {
            await dbContext.Tours.LoadAsync();


            _currentOrder.TourId = _tourId;

            if (!IsEdit)
            {
                _currentOrder.CreationDate = DateTimeOffset.Now;
                _currentOrder.OrderStatus  = OrderStatus.Active;
                _currentOrder.ClientId     = _clientId;



                if (HasInsurances)
                {
                    var insIds = _insurancesDto.Select(x => x.Id);

                    foreach (var ins in insIds)
                    {
                        var i = await dbContext.Insurances.FindAsync(ins);

                        i.Orders = new List <Order>();
                        i.Orders.Add(_currentOrder);
                    }
                }
                var placements = _placementsDto.Select(x =>
                {
                    var inst   = mapper.MapTo <PlacementDto, Placement>(x);
                    inst.Order = _currentOrder;
                    return(inst);
                });

                dbContext.Orders.Add(_currentOrder);
                dbContext.Placements.AddRange(placements);
            }
            else
            {
                dbContext.Entry(_currentOrder).State = EntityState.Modified;
            }

            try
            {
                await dbContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public async Task<bool> ApplyOrder()
        {
            await dbContext.Services.LoadAsync();
            _currentOrder.FullCost = _fullCost;
            // при редактировании ???
            _currentOrder.OrderedProducts = _orderedProducts.ToList();


            foreach(var op in _orderedProducts)
            {
                var p = await dbContext.Products.FindAsync(op.ProductId);
                p.StorageCount -= op.Count;
                dbContext.Entry(p).State = EntityState.Modified;
            }

            if (!IsEdit)
            {
                _currentOrder.CreationDate = DateTimeOffset.Now;
                _currentOrder.OrderStatus = OrderStatus.Active;
                _currentOrder.ClientId = _clientId;
                dbContext.Orders.Add(_currentOrder);
                
            }
            else
            {
                //Удаление старых
                dbContext.OrderedProducts.RemoveRange(
                    dbContext.OrderedProducts.Where(x => x.OrderId == _currentOrder.Id));

                dbContext.Entry(_currentOrder).State = EntityState.Modified;
            }
            foreach (var sId in _services)
            {
                var serv = await dbContext.Services.FindAsync(sId);
                serv.Orders = new List<Order> { _currentOrder };
                dbContext.Entry(serv).State = EntityState.Modified;
            }

            try
            {
                await dbContext.SaveChangesAsync();
            }
            catch(Exception ex)
            {
                ErrorMessage = ex.Message;
                return false;
            }

            return true;
        }
        public async Task <bool> TryRegister(string pass, string login)
        {
            await allDbContext.Clients.LoadAsync();

            if (await allDbContext.Clients.FirstOrDefaultAsync(x => x.Password == pass) != null)
            {
                ErrorMessage = "Такой пароль уже есть";
                return(false);
            }

            _client = new Client {
                Login = login, Email = Email, Name = _name, Password = pass
            };
            allDbContext.Clients.Add(_client);

            try
            {
                await allDbContext.SaveChangesAsync();

                Registered?.Invoke();
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(false);
            }
            return(true);
        }
Exemplo n.º 6
0
        public async Task <bool> ApplyDeclaration()
        {
            if (_profileId == -1)
            {
                throw new ArgumentException("Профиль не был установлен");
            }


            if (isEdit)
            {
                dbContext.Entry(_currentDec).State = EntityState.Modified;
            }
            else
            {
                _currentDec.ProfileId    = _profileId;
                _currentDec.CreatingDate = DateTime.Now;
                dbContext.Declarations.Add(_currentDec);
            }

            try
            {
                await dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                return(false);
            }
        }
Exemplo n.º 7
0
        public async Task <bool> ApplyOrder()
        {
            await dbContext.Services.Include(x => x.Orders).LoadAsync();

            foreach (var servId in _services)
            {
                var serv = await dbContext.Services.FindAsync(servId);

                serv.Orders?.Add(_currentOrder);
                dbContext.Entry(serv).State = EntityState.Modified;
            }

            _currentOrder.FullCost = _fullCost;



            if (!IsEdit)
            {
                _currentOrder.CreationDate = DateTimeOffset.Now;
                _currentOrder.OrderStatus  = OrderStatus.Active;
                _currentOrder.ClientId     = _clientId;
                dbContext.Orders.Add(_currentOrder);
            }
            else
            {
                dbContext.Entry(_currentOrder).State = EntityState.Modified;
            }

            try
            {
                await dbContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var users = grid.ItemsSource;

            foreach (var user in users)
            {
                context.Entry(user).State = EntityState.Modified;
            }



            await context.SaveChangesAsync();

            MessageBox.Show("Обновлено");
        }
Exemplo n.º 9
0
        /// <summary>
        /// УСТАНОВКА КАК ТЕКЩУЕГО ПОЛЬЗОВАТЕЛЯ НЕ ПРОИЗВОДИТСЯ
        /// </summary>
        /// <returns></returns>

        public async Task <int> RegisterAsync(bool setupUser = true)
        {
            if (_curProfile == null)
            {
                throw new ArgumentException("Профиль не был загружен");
            }


            await db.Profiles.LoadAsync();

            if (await db.Profiles.FirstOrDefaultAsync(x => x.Password == _passw) != null)
            {
                ErrorMessage = "Такой пароль уже есть";
                return(-1);
            }

            Profile profile = mapper.MapTo <ProfileDto, Profile>(_curProfile);

            profile.Password = _passw;
            db.Profiles.Add(profile);

            try
            {
                await db.SaveChangesAsync();

                if (setupUser)
                {
                    _curProfile.Id = profile.Id;
                    userService.SetupUser(_curProfile);
                }

                return(profile.Id);
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(-1);
            }
        }
Exemplo n.º 10
0
 public async Task RemoveOrder(Order order)
 {
     dbContext.Orders.Remove(order);
     await dbContext.SaveChangesAsync();
 }
Exemplo n.º 11
0
        public async Task <bool> ApplyOrderAndCompleteAsync(int clientId)
        {
            if (HasOrderParams && _style == null)
            {
                ErrorMessage = "Style is not setted";
                return(false);
            }

            await dbContext.Orders.LoadAsync();

            var order = Order;

            order.CommonCost = GetCommonCost();
            order.ClientId   = clientId;

            await dbContext.Services.Include(x => x.Orders).LoadAsync();

            foreach (var sId in _services.Select(x => x.Id))
            {
                var serv = await dbContext.Services.FindAsync(sId);

                serv.Orders?.Add(order);
                dbContext.Entry(serv).State = EntityState.Modified;
            }

            if (order.StartWorkingDate1.HasValue)
            {
                order.StartWorkingDate = order.StartWorkingDate1.Value;
            }

            order.CreationDate = DateTime.Now;

            dbContext.Orders.Add(order);


            if (HasOrderParams)
            {
                await dbContext.OrderDetails.LoadAsync();

                var orderDtl = new OrderDetail
                {
                    Area            = OrderParams.Area,
                    FloorsHeight    = OrderParams.FloorsHeight,
                    HouseType       = OrderParams.HouseType,
                    IsWallAlignment = OrderParams.IsWallAlignment,
                    RoomsCount      = OrderParams.Rooms,
                    Order           = Order,
                    StyleId         = _styleId,
                };

                dbContext.OrderDetails.Add(orderDtl);
            }

            try
            {
                await dbContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(false);
            }
            return(true);
        }