Ejemplo n.º 1
0
        private void Init()
        {
            SupplierOrderDetailsVis = Visibility.Collapsed;
            SupplierOrderDetailsVM  = new SupplierOrderDetailsVM(new SupplierOrderView()
            {
                id = 0
            });
            ProcuratoriesListVM = new ProcuratoriesListVM(auction);

            if (auction.Id == 0)
            {
            }
            else
            {
                SupplierOrdersList = SupplierOrderService.ReadSupplierOrders(auction.Id);
            }
        }
        public void UpdateSupplierOrderView(int supplierOrderId)
        {
            if (supplierOrderId == 0)
            {
                SupplierOrder = new SupplierOrderView()
                {
                    id = 0
                };

                SelectedSupplier = new Supplier();
                SelectedBroker   = BrokersList[0];
                SelectedContract = new Contract();
                SelectedRate     = new RatesList();
            }
            else
            {
                SupplierOrder    = SupplierOrderService.ReadSupplierOrder(supplierOrderId);
                SelectedSupplier = suppliersListStorage.FirstOrDefault(s => s.Id == SupplierOrder.supplierId);
                SearchCompany    = SelectedSupplier.Name;

                if (SupplierOrder.brokerId != null)
                {
                    SelectedBroker = BrokersList.FirstOrDefault(s => s.Id == SupplierOrder.brokerId);
                }
                else
                {
                    SelectedBroker = null;
                }

                if (SupplierOrder.brokerId != null)
                {
                    ContractsList    = DictionariesService.ReadContracts(SelectedSupplier.companyId, SelectedBroker.Id);
                    SelectedContract = ContractsList.FirstOrDefault(c => c.id == SupplierOrder.contractId);
                }
                else
                {
                    ContractsList = new List <Contract>();
                }
            }
        }
 public void UpdateProcuratory(int procuratoryId)
 {
     Procuratory = SupplierOrderService.ReadProcuratory(procuratoryId);
 }
 public void UpdateListView(int auctionId, int supplierId)
 {
     ProcuratoriesList = SupplierOrderService.ReadProcuratories(auctionId, supplierId);
 }
        public HttpResponseMessage GenerateSupplierOrder(int auctionId, [FromUri]  List <int> lots)
        {
            if (CurrentUser == null || CurrentUser.SupplierId == 0)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            if (lots == null || lots.Count == 0)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var orders        = DataManager.GetOrders(auctionId: auctionId);
            var auction       = DataManager.GetAuction(auctionId);
            var supplierOrder = DataManager.GetSupplierOrder(auctionId, CurrentUser.SupplierId);

            if (orders.Count == 0 || auction == null || supplierOrder == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            var order = orders[0];

            var templateRequisite = ArchiveManager.GetTemplateRequisite((MarketPlaceEnum)auction.SiteId, DocumentTemplateEnum.SupplierOrder);

            if (templateRequisite == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotImplemented);
            }

            var localPath = ArchiveManager.LoadTemplateToLocalStorage(templateRequisite);

            if (string.IsNullOrEmpty(localPath))
            {
                var responceException = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                responceException.Headers.Add("X-Error-Description", "Error load template supplier order.");
                throw new HttpResponseException(responceException);
            }


            order.Auction = auction;

            foreach (var lot in order.Auction.Lots)
            {
                if (!lots.Contains(lot.Id))
                {
                    order.Auction.Lots.Remove(lot);
                    continue;
                }
            }

            order.Auction.SupplierOrders = new System.Collections.ObjectModel.ObservableCollection <SupplierOrder>()
            {
                supplierOrder
            };
            SupplierOrderService.CreateSupplierOrder(order, localPath);

            var fileName     = string.Format("{0}.{1}", SUPPLIER_ORDER_FILE_NAME, templateRequisite.extension);
            var responceFile = HttpResponceFile.Create(fileName, localPath);

            if (responceFile == null)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }

            return(responceFile);
        }