public ICollection <OrderVM> GetAll()
        {
            try
            {
                var deliveries = _unitOfWork.RepositoryCustom <IDeliveryRepository>().GetDeliveryRouteLoad();

                var deliveriesVMs = _mapper.Map <IList <OrderVM> >(deliveries);
                return(deliveriesVMs);
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <DeliveryApplicationService>("Unexpected error fetching get delivery", nameof(this.GetAll), ex);
            }
        }
예제 #2
0
        public ICollection <ClientProductValueVM> ConnectRouteToClient(ICollection <ClientProductValueVM> clientsProductsVMs)
        {
            try
            {
                var clientsProducts = _mapper.Map <IList <ClientProductValue> >(clientsProductsVMs);
                _unitOfWork.Repository <ClientProductValue>().AddRange(clientsProducts);
                _unitOfWork.CommitSync();

                return(clientsProductsVMs);
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ProductApplicationService>("Unexpected error fetching connect Route to Client", nameof(this.ConnectRouteToClient), ex);
            }
        }
예제 #3
0
        public PictureVM Add(PictureVM entity)
        {
            try
            {
                var picture = _mapper.Map <Picture>(entity);
                _unitOfWork.Repository <Picture>().Add(picture);
                _unitOfWork.CommitSync();

                return(_mapper.Map <PictureVM>(picture));;
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ConfigurationApplicationService>("Unexpected error fetching add picture", nameof(this.Add), ex);
            }
        }
        public ICollection <ClientVM> GetAvailable(Guid routeID)
        {
            try
            {
                var route   = _unitOfWork.Repository <Route>().GetById(routeID);
                var clients = _unitOfWork.RepositoryCustom <IClientRepository>().GetAvailable(routeID, route.ClientOriginID);

                var clientsVMs = _mapper.Map <IList <ClientVM> >(clients);
                return(clientsVMs);
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ClientApplicationService>("Unexpected error fetching all available clients", nameof(this.GetAvailable), ex);
            }
        }
예제 #5
0
        public AddressVM Add(AddressVM entity)
        {
            try
            {
                var address = _mapper.Map <Address>(entity);
                _unitOfWork.Repository <Address>().Add(address);
                _unitOfWork.CommitSync();

                return(_mapper.Map <AddressVM>(address));;
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <AddressApplicationService>("Unexpected error fetching add sale", nameof(this.Add), ex);
            }
        }
예제 #6
0
        public ICollection <Client> GetByRouteID(Guid routeID)
        {
            try
            {
                var query = _context.Set <Client>()
                            .Join(_context.Set <RouteClient>(),
                                  cl => cl.Id,
                                  rt => rt.ClientID,
                                  (cl, rt) => new { Client = cl, rt.RouteID })

                            .Where(x => x.RouteID == routeID)
                            .Select(x => x.Client);

                return(query.ToList());
            }
            catch (Exception ex)
            {
                throw CustomException.Create <BoxRepository>("Unexpected error fetching GetByRouteID", nameof(this.GetByRouteID), ex);
            }
        }
예제 #7
0
        public Task <ProductVM> AddAsync(ProductVM entity)
        {
            try
            {
                var product = _mapper.Map <Product>(entity);

                _unitOfWork.Repository <Product>().AddAsync(product);
                _unitOfWork.CommitSync();

                return(Task.FromResult(entity));
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ProductApplicationService>("Unexpected error fetching add delivery", nameof(this.AddAsync), ex);
            }
        }
예제 #8
0
 public T AddUpdate(T entity)
 {
     try
     {
         if (_context.Entry <T>(entity).State == EntityState.Added)
         {
             _context.Set <T>().Add(entity);
         }
         else if (_context.Entry <T>(entity).State == EntityState.Modified)
         {
             _context.Set <T>().Attach(entity);
             _context.Entry(entity).State = EntityState.Modified;
         }
         return(entity);
     }
     catch (Exception ex)
     {
         throw CustomException.Create <T>("Unexpected error fetching AddUpdate", nameof(this.AddUpdate), ex);
     }
 }
예제 #9
0
        public ICollection <Box> GetBoxesByBoxTypeIDWithProductItems(Guid boxTypeID, int quantity)
        {
            try
            {
                var query = _context.Set <Box>()

                            .Include(x => x.BoxesChildren)
                                            // .Include(b => b.BoxesProductItems).ThenInclude(z => z.ProductItem)
                            .AsEnumerable() // <-- Force full execution (loading) of the above
                            .Where(x => x.BoxTypeID == boxTypeID && x.BoxParent == null)
                            .OrderByDescending(x => x.DateModified)
                            .Take(quantity);

                return(query.ToList());
            }
            catch (Exception ex)
            {
                throw CustomException.Create <BoxRepository>("Unexpected error fetching Get boxes with product items", nameof(this.GetBoxesByBoxTypeIDWithProductItems), ex);
            }
        }
예제 #10
0
        public ICollection <Box> GetBoxesByBoxWithChildren(Guid boxID)
        {
            try
            {
                var query = _context.Set <Box>()
                            .Include(x => x.BoxType).ThenInclude(p => p.Picture)
                            //.Include(x => x.Product).ThenInclude(z => z.Picture)

                            .Include(x => x.BoxesChildren)
                            // .Include(b => b.BoxesProductItems).ThenInclude(z => z.ProductItem)
                            .AsEnumerable() // <-- Force full execution (loading) of the above
                            .Where(x => x.Id == boxID && x.BoxParent == null);

                return(query.ToList());
            }
            catch (Exception ex)
            {
                throw CustomException.Create <BoxRepository>("Unexpected error fetching Get boxes with product items", nameof(this.GetBoxesByBoxTypeIDWithProductItems), ex);
            }
        }
        public OrderVM GetResumeDeliveryById(Guid deliveryID)
        {
            {
                try
                {
                    var delivery = _unitOfWork.RepositoryCustom <IDeliveryRepository>().GetResumeDeliveryById(deliveryID);

                    var deliveryVM = _mapper.Map <OrderVM>(delivery);
                    return(deliveryVM);
                }
                catch (CustomException exc)
                {
                    throw exc;
                }
                catch (Exception ex)
                {
                    throw CustomException.Create <DeliveryApplicationService>("Unexpected error fetching get delivery", nameof(this.GetByIdAsync), ex);
                }
            }
        }
예제 #12
0
        public async Task <T> UpdateAsync(T updated)
        {
            try
            {
                if (updated == null)
                {
                    return(null);
                }

                _context.Set <T>().Attach(updated);
                _context.Entry(updated).State = EntityState.Modified;
                //  await _unitOfWork.Commit();

                return(updated);
            }
            catch (Exception ex)
            {
                throw CustomException.Create <T>("Unexpected error fetching update", nameof(this.UpdateAsync), ex);
            }
        }
        public ICollection <RouteClientVM> ConnectRouteToClient(ICollection <RouteClientVM> routesClientsVM)
        {
            try
            {
                var routesClients = _mapper.Map <List <RouteClient> >(routesClientsVM);

                var routeClientReturn = _unitOfWork.Repository <RouteClient>().AddRange(routesClients);
                _unitOfWork.CommitSync();

                return(routesClientsVM);
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ClientApplicationService>("Unexpected error fetching connect Route to Client", nameof(this.ConnectRouteToClient), ex);
            }
        }
예제 #14
0
        public T Update(T updated)
        {
            try
            {
                if (updated == null)
                {
                    return(null);
                }

                _context.Set <T>().Attach(updated);
                _context.Entry(updated).State = EntityState.Modified;
                //   _context.SaveChanges();

                return(updated);
            }
            catch (Exception ex)
            {
                throw CustomException.Create <T>("Unexpected error fetching update", nameof(this.Update), ex);
            }
        }
        public RouteVM Add(RouteVM entity)
        {
            try
            {
                var route = _mapper.Map <Route>(entity);

                _unitOfWork.Repository <Route>().Add(route);
                _unitOfWork.CommitSync();

                return(entity);
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ClientApplicationService>("Unexpected error fetching add route", nameof(this.Add), ex);
            }
        }
        public void Delete(Guid id)
        {
            try
            {
                var Route = _unitOfWork.Repository <Route>().GetById(id);

                if (Route != null)
                {
                    _unitOfWork.Repository <Route>().Delete(Route);
                    _unitOfWork.CommitSync();
                }
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ClientApplicationService>("Unexpected error fetching delete route", nameof(this.Delete), ex);
            }
        }
예제 #17
0
        public ICollection <ProductItemVM> GetProductsItems()
        {
            try
            {
                var productsItems = _unitOfWork.Repository <ProductItem>().GetAll();
                var products      = _unitOfWork.Repository <Product>().GetAll();

                productsItems = productsItems.Select(x => { x.Product = (from p in products where p.Id == x.ProductID select p).FirstOrDefault(); return(x); }).OrderBy(x => x.Barcode).ToList();

                var productsItemsVMs = _mapper.Map <IList <ProductItemVM> >(productsItems);
                return(productsItemsVMs);
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ProductApplicationService>("Unexpected error fetching get product items", nameof(this.GetProductsItems), ex);
            }
        }
예제 #18
0
        public void Delete(Guid id)
        {
            try
            {
                var product = _unitOfWork.Repository <Product>().GetById(id);

                if (product != null)
                {
                    _unitOfWork.Repository <Product>().Delete(product);
                    _unitOfWork.CommitSync();
                }
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ProductApplicationService>("Unexpected error fetching delete delivery", nameof(this.Delete), ex);
            }
        }
        public ICollection <ClientVM> GetByRouteIDAndOrderID(Guid routeID, Guid orderID)
        {
            try
            {
                var clients = _unitOfWork.RepositoryCustom <IClientRepository>().GetByRouteID(routeID);
                var details = _unitOfWork.Repository <DeliveryDetail>().FindBy(x => x.OrderID == orderID).ToList();

                var result = clients.Select(x => { x.DeliveriesDetails = details.Where(d => d.ClientID == x.Id).ToList(); return(x); }).ToList();

                IList <ClientVM> clientsVM = _mapper.Map <List <ClientVM> >(result);

                return(clientsVM);
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ClientApplicationService>("Unexpected error fetching get client", nameof(this.GetByRouteIDAndOrderID), ex);
            }
        }
예제 #20
0
        public void Add(CreateBoxVM entity)
        {
            try
            {
                _unitOfWork.SetTrackAll();
                var boxtype = _unitOfWork.Repository <BoxType>().GetById(entity.BoxTypeID);

                int totalProductItemsToStock = 0;

                foreach (var barcode in entity.TagsBarcodes)
                {
                    Box box = _unitOfWork.Repository <Box>().Find(b => b.GraphicCodes.BarcodeEAN13 == barcode) ?? Box.FactoryCreate(boxtype, barcode);

                    if (entity.HasMovementStock)
                    {
                        int totalItemsByBox = SumTotalProductItemsForStock(entity, boxtype);
                        totalProductItemsToStock += totalItemsByBox;

                        box.StoreProductsItems(entity.ProductID, totalItemsByBox);
                    }
                    _unitOfWork.Repository <Box>().AddUpdate(box);
                }

                if (entity.HasMovementStock)
                {
                    AddStockAndMovement(entity, boxtype, totalProductItemsToStock);
                }
                _unitOfWork.CommitSync();
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <BoxApplicationService>("Unexpected error fetching add boxes", nameof(this.Add), ex);
            }
        }
예제 #21
0
        public ICollection <ProductItem> GetOrderProductItemByDeliveryID(Guid orderID)
        {
            try
            {
                var query = _context.Set <ProductItem>()
                            .Include(b => b.Product)

                            .Include(x => x.BoxesProductItems).ThenInclude(b => b.Box).ThenInclude(bt => bt.BoxType)
                            .Join(_context.Set <OrderProductItem>(),
                                  ordP => ordP.Id,
                                  pi => pi.ProductItemID,
                                  (productItem, orderProductItem) => new { ProductItem = productItem, OrderProductItem = orderProductItem })

                            .Where(x => x.OrderProductItem.OrderID == orderID && x.ProductItem.FlowStep.EFlowStep == CrossCutting.Enums.EFlowStep.Expedition)
                            .Select(x => x.ProductItem);

                return(query.ToList());
            }
            catch (Exception ex)
            {
                throw CustomException.Create <BoxRepository>("Unexpected error fetching Get boxes with product items", nameof(this.GetBoxesByBoxTypeIDWithProductItems), ex);
            }
        }
        public void FinishDelivery(Guid orderID)
        {
            try
            {
                _unitOfWork.SetTrackAll();
                var order = _unitOfWork.Repository <Order>().GetById(orderID);
                order.Route = _unitOfWork.Repository <Route>().GetById(order.RouteID);
                order.Close();

                _unitOfWork.Repository <Order>().Update(order);
                _unitOfWork.CommitSync();
            }
            catch (CustomException exc)
            {
                _unitOfWork.Rollback();
                throw exc;
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();
                throw CustomException.Create <SaleApplicationService>("Unexpected error fetching add sale", nameof(this.FinishDelivery), ex);
            }
        }
예제 #23
0
        public void AddBoxType(BoxTypeVM entity)
        {
            try
            {
                var boxType = _mapper.Map <BoxType>(entity);

                if (!boxType.ComponentValidator.Validate(boxType, new BoxTypeValidator()))
                {
                    throw new CustomException(string.Join(", ", boxType.ComponentValidator.ValidationResult.Errors.Select(x => x.ErrorMessage)));
                }

                _unitOfWork.Repository <BoxType>().Add(boxType);
                _unitOfWork.CommitSync();
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <BoxApplicationService>("Unexpected error fetching add product", nameof(this.Add), ex);
            }
        }
예제 #24
0
        public void AddTraceType(TrackingTypeVM entity)
        {
            try
            {
                var traceType = _mapper.Map <TrackingType>(entity);

                //if (!boxType.ComponentValidator.Validate(boxType, new BoxTypeValidator()))
                //{
                //    throw new CustomException(string.Join(", ", boxType.ComponentValidator.ValidationResult.Errors.Select(x => x.ErrorMessage)));
                //}

                _unitOfWork.Repository <TrackingType>().Add(traceType);
                _unitOfWork.CommitSync();
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <TrackingApplicationService>("Unexpected error fetching add trace type", nameof(this.AddTraceType), ex);
            }
        }
예제 #25
0
        public int AddRange(ICollection <Bank> entity)
        {
            try
            {
                //if (!client.ComponentValidator.IsValid)
                //{
                //    entity.SetNotifications(client.ComponentValidator.GetNotifications());
                //    return entity;
                //}
                var result = _unitOfWork.Repository <Bank>().AddRange(entity);
                _unitOfWork.CommitSync();

                return(result);
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <BankAppService>("Unexpected error fetching all Addrange bank", nameof(this.AddRange), ex);
            }
        }
예제 #26
0
        //Mobile
        public ICollection <string> GetListBarcodes(int quantity)
        {
            try
            {
                IList <GraphicCodes> listGraphicCodes = new List <GraphicCodes>(quantity);

                for (int i = 0; i < quantity; i++)
                {
                    GraphicCodes graphicCodes = GraphicCodes.FactoryCreate();
                    listGraphicCodes.Add(graphicCodes);
                }

                return(listGraphicCodes.Select(gc => gc.BarcodeEAN13).ToList());
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <BoxApplicationService>("Unexpected error fetching Barcodes", nameof(this.GetListBarcodes), ex);
            }
        }
        public ICollection <RouteClientVM> RemoveRouteFromClient(ICollection <RouteClientVM> routesClientsVM)
        {
            try
            {
                var routesClients = _mapper.Map <List <RouteClient> >(routesClientsVM);

                foreach (var item in routesClients)
                {
                    _unitOfWork.Repository <RouteClient>().Delete(item);
                }
                _unitOfWork.CommitSync();

                return(routesClientsVM);
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ClientApplicationService>("Unexpected error fetching remove Route to Client", nameof(this.RemoveRouteFromClient), ex);
            }
        }
예제 #28
0
        public void AddBoxStockWithBoxes(Guid boxTypeID, Guid trackingTypeID, Guid clientID, Guid boxTypeChildID, int quantity)
        {
            try
            {
                var boxesChildrem = _unitOfWork.RepositoryCustom <IProductRepository>().GetBoxesInStockByBoxTypeIDAndClientID(boxTypeChildID, clientID);

                var         boxType             = _unitOfWork.Repository <BoxType>().GetById(boxTypeID);
                List <Box>  boxesUpdateChildrem = new List <Box>();
                IList <Box> boxes = new List <Box>();

                for (int i = 0; i < quantity; i++)
                {
                    var updateList = boxesChildrem.Where(x => !boxesUpdateChildrem.Any(p => p.Id == x.Id)).Take(boxType.MaxProductsItems).ToList();

                    Box box = Box.FactoryCreate(boxTypeID, boxType, i);
                    box.FlowStep.SetInStock();
                    boxesUpdateChildrem.AddRange(box.AddChildren(updateList));
                    box.AddTracking(trackingTypeID, clientID);
                    box.BoxType       = null;
                    box.BoxesChildren = null;
                    boxes.Add(box);
                }

                _unitOfWork.Repository <Box>().AddRange(boxes);
                _unitOfWork.Repository <Box>().UpdateRange(boxesUpdateChildrem);

                _unitOfWork.CommitSync();
            }
            catch (CustomException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ProductApplicationService>("Unexpected error fetching Add Stock Product", nameof(this.AddStockProduct), ex);
            }
        }
예제 #29
0
        public IEnumerable <T> Filter(Expression <Func <T, bool> > filter = null, Func <IQueryable <T>, IOrderedQueryable <T> > orderBy = null, string includeProperties = "", int?page = null,
                                      int?pageSize = null)
        {
            try
            {
                IQueryable <T> query = _context.Set <T>();
                if (filter != null)
                {
                    query = query.Where(filter);
                }

                if (orderBy != null)
                {
                    query = orderBy(query);
                }

                if (includeProperties != null)
                {
                    foreach (
                        var includeProperty in includeProperties.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        query = query.Include(includeProperty);
                    }
                }

                if (page != null && pageSize != null)
                {
                    query = query.Skip((page.Value - 1) * pageSize.Value).Take(pageSize.Value);
                }

                return(query.ToList());
            }
            catch (Exception ex)
            {
                throw CustomException.Create <T>("Unexpected error fetching filter", nameof(this.Filter), ex);
            }
        }
예제 #30
0
        public ICollection <Box> GetBoxesAvailableToOrderByRouteID(Guid routeID)
        {
            try
            {
                var query = _context.Set <Box>();
                // .Include(x => x.BoxesChildren)
                // .Include(b => b.BoxesProductItems).ThenInclude(z => z.ProductItem)
                // .AsEnumerable() // <-- Force full execution (loading) of the above
                //   .Where(x => (x.FlowStep.EFlowStep == CrossCutting.Enums.EFlowStep.InStock || x.FlowStep.EFlowStep == CrossCutting.Enums.EFlowStep.CrossDocking) && x.BoxParentID == null)
                // .Join(_context.Set<Tracking>(),
                //   pdi => pdi.Id,
                //   track => track.BoxID,
                //   (pdi, track) => new { Box = pdi, Tracking = track })
                // .Join(_context.Set<TrackingType>(),
                //   track => track.Tracking.TrackingTypeID,
                //   tt => tt.Id,
                //   (track, tt) => new { track.Box, track.Tracking, TrackingType = tt })
                // .Join(_context.Set<TrackingClient>(),
                //   track => track.Tracking.Id,
                //   cl => cl.TrackingID,
                //   (tr, trcl) => new { tr.Box, tr.Tracking, TrackingClient = trcl, tr.TrackingType })
                // .Join(_context.Set<Route>(),
                //   rt => rt.TrackingClient.ClientID,
                //   c**t => c**t.ClientOriginID,
                //   (tr, rt) => new { tr.Box, tr.Tracking, tr.TrackingClient, tr.TrackingType, Route = rt })
                //   .Where(x => x.TrackingType.TrackType == CrossCutting.Enums.ETrackType.Place &&
                //          (x.Box.FlowStep.EFlowStep == CrossCutting.Enums.EFlowStep.InStock || x.Box.FlowStep.EFlowStep == CrossCutting.Enums.EFlowStep.CrossDocking) &&
                //          x.Route.Id == routeID)
                //.Select(x => x.Box);

                return(query.ToList());
            }
            catch (Exception ex)
            {
                throw CustomException.Create <ProductRepository>("Unexpected error fetching total", nameof(this.GetBoxesAvailableToOrderByRouteID), ex);
            }
        }