public FileDelivery GetFile(DocumentDelivery documentDelivery, bool attachments = true)
        {
            var request = new RestRequest("documents/deliveries/{id}", Method.GET);

            request.AddHeader("Authorization", "Bearer " + ApiKey);
            request.AddUrlSegment("id", documentDelivery.DocumentDeliveryId);
            request.AddQueryParameter("attachments", attachments.ToString());

            var response = client.Execute(request);

            if (response.ErrorException != null)
            {
                throw new Exception(response.ErrorException.Message);
            }
            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(string.IsNullOrEmpty(response.Content) ? response.StatusDescription : response.Content);
            }

            var contentDisposition = response.Headers.SingleOrDefault(a => a.Name == "Content-Disposition").Value.ToString().Split(';');
            var filename           = contentDisposition.Single(a => a.Contains("filename=")).Replace("filename=", "").Replace("\"", "").Trim();

            var fileDelivery = new FileDelivery();

            fileDelivery.FileName = filename;
            fileDelivery.File     = response.RawBytes;
            fileDelivery.FilePath = documentDelivery.Subscription.FilePath;
            return(fileDelivery);
        }
Пример #2
0
        public ActionResult AddOrUpdateGeneralAndSaleInfo(GeneralAndSaleInfoViewModel model)
        {
            var data = new MobileResponseModel();

            try
            {
                var document     = GenericFactory.Business.GetDocument(model.Id);
                var customerCode = "";
                if (document != null)
                {
                    document.BiddingStatusId    = model.IsDraft ? (int)WorkflowStatus.Draft : (int)WorkflowStatus.RequestForPrice;
                    document.ConfirmedPriceDays = model.ConfirmPriceDays;
                    document.DeliveryDays       = model.DeliveryDays;
                    document.UserId             = model.SaleUserId;
                    this.UpdateDocument(document, customerCode);
                }
                else
                {
                    var _documentId = Guid.NewGuid();
                    document = new Document
                    {
                        Id = _documentId,
                        DocumentStatusId   = model.IsDraft ? (int)WorkflowStatus.Draft : (int)WorkflowStatus.RequestForPrice,
                        ConfirmedPriceDays = model.ConfirmPriceDays,
                        DeliveryDays       = model.DeliveryDays,
                        UserId             = model.SaleUserId,
                        CustomerId         = new Guid(AppSettingHelper.DummyCustomerId),
                        ContactId          = new Guid(AppSettingHelper.DummyContactId)
                    };
                    var delivery = new DocumentDelivery
                    {
                        Id         = Guid.NewGuid(),
                        DocumentId = _documentId,
                        Address1   = ""
                    };
                    document.DocumentDeliveries.Add(delivery);
                    this.CreateDocument(document, customerCode);
                }
                data.Datas = new
                {
                    Id = document.Id.ToString()
                };
            }
            catch (Exception ex)
            {
                data.Status       = false;
                data.ErrorCode    = "001";
                data.ErrorMessage = ex.Message;
                data.MessageId    = "";
                data.TimeStamp    = "";
            }
            return(new JsonCamelCaseResult(data, JsonRequestBehavior.AllowGet));
        }
        public async Task <DocumentDelivery> post(DocumentDeliveryRequest request)
        {
            var upload = new UploadFiles();

            DocumentDelivery model = new DocumentDelivery();

            model.Delivery = await _delivery.GetByIdAsync(request.DeliveryId);

            model.Format  = request.Format;
            model.Name    = request.Name;
            model.Path    = upload.Upload(request.Name, request.Format, request.Doc);
            model.Student = await _student.GetByEmail(request.Student);

            var newModel = await _repository.PostAsync(model);

            return(_repository.Find(x => x.Id == newModel.Id, x => x.Delivery, x => x.Student));
        }
Пример #4
0
        public static Document ToEntity(this DocumentViewModel viewModel)
        {
            Guid _documentId = Guid.NewGuid();

            if (!string.IsNullOrEmpty(viewModel.Id))
            {
                _documentId = new System.Guid(viewModel.Id);
            }
            var document = new Document();

            document.Id = _documentId;
            document.BiddingStatusId = (int)BiddingStatus.Waiting;
            //document.ExpiryDate = DateTime.Parse(viewModel.ExpirationDate);
            document.UserId     = viewModel.SaleUserId;
            document.CustomerId = new System.Guid(viewModel.CustomerId);
            document.ContactId  = new System.Guid(viewModel.ContactId);
            document.PoNumber   = viewModel.PoNumber;
            //document.CustomerBranchId = new System.Guid(viewModel.CustomerBranchId);
            foreach (var i in viewModel.Items)
            {
                var itemId = Guid.NewGuid();
                var item   = new DocumentProductItem
                {
                    Id            = itemId,
                    ProductId     = new System.Guid(i.ProductId),
                    ProductUnitId = new System.Guid(i.ProductUnitId),
                    Amount        = i.Amount,
                    PricePerUnit  = (decimal)i.PricePerUnit
                };
                var printOption1 = new ProductItemPrintOptional();
                var printOption2 = new ProductItemScreenOptional();
                var printOption3 = new ProductItemSewOptional();
                var printStatus  = (ItemOptionStatus)i.PrintOption.SelectedOption;
                switch (printStatus)
                {
                case ItemOptionStatus.ExistingPattern:
                {
                    printOption1.Id = Guid.NewGuid();
                    printOption1.OptionalStatusId = 1;
                    printOption1.ProductItemId    = itemId;
                    printOption1.PatternId        = new Guid(i.PrintOption.PatternId.ToString());
                    break;
                }

                case ItemOptionStatus.NewPattern:
                {
                    printOption1.Id = Guid.NewGuid();
                    printOption1.OptionalStatusId = 2;
                    printOption1.ColorCodeId      = new Guid(i.PrintOption.ColorId);
                    printOption1.ProductItemId    = itemId;

                    break;
                }

                case 0:
                {
                    break;
                }
                }
                var screenStatus = (ItemOptionStatus)i.ScreenOption.SelectedOption;
                switch (screenStatus)
                {
                case ItemOptionStatus.ExistingPattern:
                {
                    printOption2.Id = Guid.NewGuid();
                    printOption2.OptionalStatusId = 1;
                    printOption2.ProductItemId    = itemId;
                    printOption2.PatternId        = new Guid(i.ScreenOption.PatternId.ToString());
                    break;
                }

                case ItemOptionStatus.NewPattern:
                {
                    printOption2.Id = Guid.NewGuid();
                    printOption2.OptionalStatusId  = 2;
                    printOption2.ColorCodeId       = new Guid(i.ScreenOption.ColorId);
                    printOption2.PatternPositionId = new Guid(i.ScreenOption.ColorId);
                    printOption2.ProductItemId     = itemId;

                    break;
                }

                case 0:
                {
                    break;
                }
                }
                var sewStatus = (ItemOptionStatus)i.SewOption.SelectedOption;
                switch (sewStatus)
                {
                case ItemOptionStatus.ExistingPattern:
                {
                    printOption3.Id = Guid.NewGuid();
                    printOption3.OptionalStatusId = 1;
                    printOption3.ProductItemId    = itemId;
                    printOption3.PatternId        = new Guid(i.SewOption.PatternId.ToString());
                    break;
                }

                case ItemOptionStatus.NewPattern:
                {
                    printOption3.Id = Guid.NewGuid();
                    printOption3.OptionalStatusId  = 2;
                    printOption3.PatternPositionId = new Guid(i.SewOption.PositionId);
                    printOption3.ProductItemId     = itemId;
                    printOption3.Remark            = i.SewOption.Remark;
                    break;
                }

                case 0:
                {
                    break;
                }
                }
                if (i.PrintOption.SelectedOption > 0)
                {
                    item.ProductItemPrintOptionals.Add(printOption1);
                }
                if (i.ScreenOption.SelectedOption > 0)
                {
                    item.ProductItemScreenOptionals.Add(printOption2);
                }
                if (i.SewOption.SelectedOption > 0)
                {
                    item.ProductItemSewOptionals.Add(printOption3);
                }
                document.DocumentProductItems.Add(item);
            }
            //document.DeliveryContactId = new System.Guid(viewModel.DeliveryContactId);
            var delivery = new DocumentDelivery
            {
                Id         = Guid.NewGuid(),
                DocumentId = _documentId,
                Address1   = viewModel.DeliveryAddress
            };

            document.DocumentDeliveries.Add(delivery);
            document.RefPriceAndRemark  = viewModel.Remark;
            document.ConfirmedPriceDays = viewModel.ConfirmPriceDays;
            document.DeliveryDays       = viewModel.DeliveryDays;
            document.IsDelete           = false;
            return(document);
        }