示例#1
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);
        }
        public async Task <bool> SetupEvac(int evacId)
        {
            if (_evac == null || _evac.Id != evacId)
            {
                //загружается совершенно другая эвакуация, история другая
                Clear();

                _evac = dbContext.Evacuations.Find(evacId);
                await dbContext.Entry(_evac).Collection("Declarations").LoadAsync();


                _currentDec = _evac.Declarations.FirstOrDefault(x => x.DecStatus == DecStatus.Active ||
                                                                x.DecStatus == DecStatus.ActivePaid);

                isEdit = _currentDec != null;

                _currentDec = _currentDec ?? new Declaration()
                {
                    ComingDate = DateTime.Now.AddDays(1)
                };

                if (!isEdit)
                {
                    _currentDec.EvacuationId = evacId;
                }
                else
                {
                    _profileId = _currentDec.ProfileId;
                }
            }
            return(isEdit);
        }
示例#3
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 ActionResult AllotmentOfPlanes(PlanesAllotments hangar)
        {
            AllDbContext db        = new AllDbContext();
            var          user      = db.Hangars.Where(n => n.HangerName == hangar.HangarName);
            var          planeUser = db.Planes.Where(n => n.PlaneID == hangar.PlaneID);

            if (ModelState.IsValid)
            {
                foreach (var i in user)
                {
                    i.isPlaneAllocated = true;
                }
                foreach (var j in planeUser)
                {
                    j.isAllotted = true;
                }
                hangar.isPlaneAllocated = true;
                hangar.ManagerID        = User.Identity.GetUserName().ToString();
                db.Entry(hangar).State  = EntityState.Added;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.HangarName = new SelectList(db.Hangars.Where(n => n.isPlaneAllocated == false && n.isActive == true), "HangerName", "HangerName");
            ViewBag.PlaneID    = new SelectList(db.Planes.Where(n => n.isAllotted == false), "PlaneID", "planeID");
            return(View(hangar));
        }
示例#5
0
        public async void Handle(string message)
        {
            bool   hasId = message.Contains("/");
            object id    = null;

            string modelTypeName = hasId ? message.Split('/')[0] : message;

            string modelName1 = modelTypeName.Substring(modelTypeName.IndexOf('.') + 1);

            var ass = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.FullName.StartsWith("DAL"));

            Type type = ass.GetType(modelTypeName);
            var  set  = allDbContext.Set(type);

            if (hasId)
            {
                id = int.Parse(message.Split('/')[1]);
                var entity = set.Find(id);
                await allDbContext.Entry(entity).ReloadAsync();
            }
            //else
            //{
            //    await set.ForEachAsync(x => allDbContext.Entry(x).Reload());
            //}

            var eventType = typeof(DataUpdated <>).MakeGenericType(type);

            var instance = Activator.CreateInstance(eventType) as IEvent;

            await eventBus.Publish(instance);
        }
示例#6
0
        protected async Task Edit(T item)
        {
            var id = idProp.GetValue(item);

            dbContext.Entry <T>(item).State = EntityState.Modified;
            await dbContext.SaveChangesAsync();

            await OnEdit();
            await OnDbChanged(id);
        }
示例#7
0
        protected async Task Edit(T item)
        {
            var id   = idProp.GetValue(item);
            T   copy = await dbContext.Set <T>().FindAsync(id);

            cloneItems.Clone(item, copy);
            dbContext.Entry <T>(copy).State = EntityState.Modified;
            await dbContext.SaveChangesAsync();

            await OnEdit();
            await OnDbChanged(id);
        }
示例#8
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);
        }
示例#9
0
        public ActionResult AddSchedule(PilotSchedule ps)
        {
            var db = new AllDbContext();

            if (ModelState.IsValid)
            {
                db.Entry(ps).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.PilotID = new SelectList(db.Pilots, "PilotID", "PilotID", ps.PilotID);
            return(View(ps));
        }
示例#10
0
        public async Task ReloadAsync(int clId)
        {
            using (var context = new AllDbContext())
            {
                await context.Orders.Where(x => x.ClientId.Equals(clId)).Include(x => x.Services).Include(x => x.OrderDetail).LoadAsync();

                _orders = context.Orders.Local.ToList();

                foreach (var ord in _orders.Where(x => x.Services.Any(y => y.NeedDetails)))
                {
                    await context.Entry(ord.OrderDetail).Reference(x => x.Style).LoadAsync();
                }
            }
        }
示例#11
0
        public ActionResult UpdateHangar(HangarDetails hangar)
        {
            var db    = new AllDbContext();
            var entry = db.Entry(hangar);

            if (ModelState.IsValid)
            {
                entry.State = EntityState.Modified;
                db.SaveChanges();
                TempData["HangarUpdate"] = "Hangar Details Updated Successfully";
                return(RedirectToAction("Hangars", "Admin"));
            }
            return(View(entry));
        }
示例#12
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("Обновлено");
        }
示例#13
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);
        }
示例#14
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);
        }