private void Init(Auction auction)
        {
            Procuratory = new Procuratory();

            if (auction.Id == 0)
            {
                LotsList = new List <Lot>();
            }
            else
            {
                LotsList = LotService.ReadLots(auction.Id);
            }
        }
        public HttpStatusCode CreateProcuratory(int auctionId)
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.MethodNotAllowed);
            }

            var scan     = HttpContext.Current.Request.Files.Get("scan");
            var template = HttpContext.Current.Request.Files.Get("template");

            if (template == null || scan == null || HttpContext.Current.Request.Form.Get("form") == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var form = JObject.Parse(HttpContext.Current.Request.Form.Get("form"));

            if (form.GetValue("lots") == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var supplierOrder = DataManager.GetSupplierOrder(auctionId, CurrentUser.SupplierId);

            if (supplierOrder == null || supplierOrder.status.Id != 15)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            List <Procuratory> procuratories = new List <Procuratory>();

            foreach (var lot in form.GetValue("lots").ToList())
            {
                if (supplierOrder.lots.Any(l => l.Id == (int)lot["Id"]))
                {
                    var procuratory = new Procuratory()
                    {
                        SupplierId   = CurrentUser.SupplierId,
                        lotId        = (int)lot["Id"],
                        MinimalPrice = (decimal)lot["Sum"]
                    };
                    procuratories.Add(procuratory);
                }
            }

            var pathToScan     = scan.SaveInTemplateFolder();
            var pathToTemplate = template.SaveInTemplateFolder();

            return(AltaTradingSystemApp.Services.ProcuratoriesService.AppendProcuratory(DataManager, ArchiveManager, procuratories, pathToTemplate, pathToScan) ? HttpStatusCode.Created : HttpStatusCode.InternalServerError);
        }
Exemple #3
0
        public HttpStatusCode CreateProcuratory(int auctionId)
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.MethodNotAllowed);
            }

            var file = HttpContext.Current.Request.Files.Get("file");

            if (file == null || HttpContext.Current.Request.Form.Get("form") == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var form = JObject.Parse(HttpContext.Current.Request.Form.Get("form"));

            if (form.GetValue("lots") == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var supplierId = (int)form.GetValue("supplierId");

            var supplierOrder = DataManager.GetSupplierOrder(auctionId, supplierId);

            if (supplierOrder == null || supplierOrder.status.Id != 15)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            var auction = DataManager.GetAuction(auctionId);

            List <Procuratory> procuratories = new List <Procuratory>();

            var archive = new ArchiveManager(DataManager);
            var fileId  = archive.PutDocument(file.InputStream, new DocumentRequisite()
            {
                date     = auction.Date,
                market   = (MarketPlaceEnum)auction.SiteId,
                number   = auction.Number,
                fileName = file.FileName,
                section  = DocumentSectionEnum.Auction,
                type     = DocumentTypeEnum.Procuratory
            });

            if (fileId < 1)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }

            foreach (var lot in form.GetValue("lots").ToList())
            {
                if (supplierOrder.lots.Any(l => l.Id == (int)lot["Id"]))
                {
                    var procuratory = new Procuratory()
                    {
                        SupplierId   = supplierId,
                        lotId        = (int)lot["Id"],
                        MinimalPrice = (decimal)lot["Sum"],
                        fileId       = fileId
                    };
                    procuratories.Add(procuratory);
                }
            }

            return(DataManager.AddProcuratories(auctionId, procuratories) ? HttpStatusCode.Created : HttpStatusCode.InternalServerError);
        }