public void AddItemAboveLimitReturnsFalse()
        {
            var po = new PurchaseOrder()
            {
                SpendLimit = 100
            };

            _purchaseOrderRepo.Add(po);

            po.TryAddItem(new LineItem(50), _purchaseOrderService);
            var item = new LineItem(51);

            Assert.False(po.TryAddItem(item, _purchaseOrderService));
        }
Пример #2
0
        public JsonResult AddUpdateData(PurchaseOrder_VM Model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    GetUserInfo(Model);

                    if (Model.POID == 0 || Model.POID == null)
                    {
                        var data = _PurchaseOrderRepo.Add(Model);
                        return(GetAddEditDeleteResponse(data, "Add"));
                    }
                    else if (Model.POID != 0 && Model.POID != null)
                    {
                        var data = _PurchaseOrderRepo.Update(Model);
                        return(GetAddEditDeleteResponse(data, "Update"));
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("PurchaseOrderController_AddUpdateData Error: ", ex);
                    return(GetAddEditErrorException(ex));
                }
            }

            return(GetModelStateIsValidException(ViewData));
        }
Пример #3
0
        public bool AddLineItem()
        {
            var poId = Guid.NewGuid().ToString();
            var po   = new PurchaseOrder(poId)
            {
                SpendLimit = 100
            };

            _purchaseOrderRepo.Add(po);
            LineItemId++;
            var lineitem1 = new LineItem(LineItemId, "LineItem1", "LineItem1", 50);

            po.AddLineItem(lineitem1, _purchaseOrderService);
            LineItemId++;
            var lineitem2 = new LineItem(LineItemId, "LineItemId2", "LineItemId2", 51);

            return(po.AddLineItem(lineitem2, _purchaseOrderService));
        }
Пример #4
0
        public async Task <PurchaseOrder> Add(NewPurchaseOrderModel model)
        {
            Validate(model);
            var reseller = GetReseller(model.CPF);
            var status   = reseller.AutoApproved ? Constants.PURCHASE_STATUS_APPROVED : Constants.PURCHASE_STATUS_WAITING_APPROVAL;
            var purchase = TinyMapper.Map <PurchaseOrder>(model);

            purchase.Id         = Guid.NewGuid();
            purchase.Status     = status;
            purchase.ResellerId = reseller.Id;
            await _purchaseRepository.Add(purchase);

            _logger.LogInformation($"[PurchaseOrderService/Add] Compra {purchase.Id} adicionada");
            return(purchase);
        }
        public void Save(PurchaseOrder purchaseOrder)
        {
            PurchaseOrder po = purchaseOrderContext.Get(purchaseOrder.Id);

            if (po == null)
            {
                purchaseOrderContext.Add(purchaseOrder);
            }
            else
            {
                po.Remark       = purchaseOrder.Remark;
                po.Status       = purchaseOrder.Status;
                po.ExpectedDate = purchaseOrder.ExpectedDate;
            }
            purchaseOrderContext.Commit();
        }
Пример #6
0
        public object Post(Models.PurchaseOrder added)
        {
            object json;
            string messageError = "";

            try
            {
                Models.PurchaseOrder posted = repository.Add(added, ref messageError);

                if (posted != null)
                {
                    json = new
                    {
                        total   = 1,
                        data    = posted,
                        success = true
                    };
                }
                else
                {
                    json = new
                    {
                        message = messageError,
                        success = false
                    };
                };
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                object error = new { message = ex.Message };

                json = new
                {
                    message = ex.Message,
                    success = false
                };
            };

            return(json);
        }
Пример #7
0
 public IActionResult AddPurchaseOrder([FromBody] PurchaseOrder model)
 {
     model.OrderNumber = GenON();
     order_repo.Add(model);
     return(new OkObjectResult(new { PurchaseOrderID = model.PurchaseOrderId }));
 }
        public void Handle(QuantityOnHandBelowReorderThresholdEvent @event)
        {
            var po = new PurchaseOrder(@event.ProductId, @event.ReorderAmount);

            _purchaseOrderRepository.Add(po);
        }
Пример #9
0
        public IActionResult InvoiceComplete()
        {
            try
            {
                PurchaseForm purchaseForm = JsonConvert.DeserializeObject <PurchaseForm>(TempData["purchaseForm"].ToString());
                EmailSender  email        = new EmailSender(_smtpSettings);

                if (purchaseForm.PersonalInformation.PaymentMethod == "Paypal")
                {
                    PayPalV2.captureOrder(purchaseForm.PayPalCapture);
                }

                purchaseForm = PurchaseOrderRepository.Add(purchaseForm);
                if (purchaseForm.Discount != null && purchaseForm.Discount.SingleUse)
                {
                    DiscountModelRepository.SetNotInUse(purchaseForm.Discount);
                }

                var bot = new DiscordBot();
                bot.RunAsync(purchaseForm).GetAwaiter().GetResult();


                string emailbody = string.Empty;
                switch (purchaseForm.PurchaseType)
                {
                case PurchaseTypeEnum.PurchaseType.SoloBoosting:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderSoloEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.DuoBoosting:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderDuoEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.WinBoosting:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderWinBoostEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.PlacementMatches:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderPlacementMatchesEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.TFTPlacement:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderTFTPlacementMatchesEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.TFTBoosting:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderTFTSoloBoostEmail", purchaseForm).Result;
                    break;

                default:
                    emailbody = JsonConvert.SerializeObject(purchaseForm);
                    break;
                }
                email.SendEmailAsync(purchaseForm.PersonalInformation.Email, $"Purchase Order", emailbody);

                if (User.Identity.IsAuthenticated)
                {
                    return(RedirectToAction("OrderDetails", "ClientArea", new { hash = EncryptionHelper.Encrypt(purchaseForm.Id) }));
                }
                else
                {
                    TempData.Put("completePurchaseForm", purchaseForm);
                    return(RedirectToAction("InvoiceDetails", "Invoice"));
                }
            }
            catch (Exception e)
            {
            }

            return(View());
        }
Пример #10
0
        public IActionResult PurchaseQuote()
        {
            try
            {
                PurchaseForm purchaseForm = JsonConvert.DeserializeObject <PurchaseForm>(TempData["purchaseFormlData"].ToString());
                EmailSender  email        = new EmailSender(_smtpSettings);

                if (purchaseForm.PersonalInformation.PaymentMethod == "Paypal")
                {
                    PayPalV2.captureOrder(purchaseForm.PayPalCapture);
                }

                PurchaseOrderRepository.Add(purchaseForm);
                if (purchaseForm.Discount != null && purchaseForm.Discount.SingleUse)
                {
                    DiscountModelRepository.SetNotInUse(purchaseForm.Discount);
                }

                var bot = new DiscordBot();
                bot.RunAsync(purchaseForm).GetAwaiter().GetResult();


                string emailbody = string.Empty;
                switch (purchaseForm.PurchaseType)
                {
                case PurchaseTypeEnum.PurchaseType.SoloBoosting:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderSoloEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.DuoBoosting:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderDuoEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.WinBoosting:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderWinBoostEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.PlacementMatches:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderPlacementMatchesEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.TFTPlacement:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderTFTPlacementMatchesEmail", purchaseForm).Result;
                    break;

                case PurchaseTypeEnum.PurchaseType.TFTBoosting:
                    emailbody = RenderPartialViewToString("EmailTemplates/PurchaseOrderTFTSoloBoostEmail", purchaseForm).Result;
                    break;

                default:
                    emailbody = JsonConvert.SerializeObject(purchaseForm);
                    break;
                }
                email.SendEmailAsync(purchaseForm.PersonalInformation.Email, $"Purchase Order", emailbody);
            }
            catch (Exception e)
            {
            }

            return(View());
        }