internal static void WorkWithFile(Byte[] file)
        {
            //1-2.IEnumerable<Sales>
            IEnumerable <Sales> sales = ParseCsv.ParseResource <Sales>(file, sale =>
            {
                sale.CreatedByUserId = adminGuid;
                sale.CreatedDateTime = DateTime.UtcNow;
            });

            // Check data whether there is a database (manager)
            ValidateData(sales);

            // write to the Sales database

            //3.AutoMapper BLL
            SalesService salesService = new SalesService(mapper);
            var          saleBLL      = MappingService.MappingForBLLEntities <BLL.Sale, BLL.Sales>(salesService, sales);

            //4.AutoMapper DAL
            SaleService saleService = new SaleService(mapper);
            var         saleDAL     = MappingService.MappingForDALEntities <DAL.Sale, BLL.Sale>(saleService, saleBLL);

            // find customers and products by their ID and, if not, create new IDs
            saleDAL = clientService.CheckNameId(saleDAL).Result;
            saleDAL = productService.CheckNameId(saleDAL).Result;

            // write to the sales database from the file
            saleService.Add(saleDAL);
            //SaveChangesWithException(saleService, "заказа");
        }
Exemplo n.º 2
0
        public void ShouldChangeSharesNumber()
        {
            // Arrange
            SalesService salesService = new SalesService(
                this.operationTableRepository,
                this.balanceTableRepository,
                this.blockedMoneyTableRepository,
                this.sharesNumberTableRepository,
                this.blockedSharesNumberTableRepository);
            var sharesNumber = new SharesNumberEntity()
            {
                Id     = 4,
                Number = 34
            };
            int newNumber = 45;

            // Act
            bool flag = salesService.ChangeSharesNumber(sharesNumber, newNumber);

            // Assert
            this.sharesNumberTableRepository.Received(1).ChangeNumber(sharesNumber.Id, newNumber);
            this.sharesNumberTableRepository.Received(1).SaveChanges();
            if (!flag)
            {
                throw new ArgumentException("The flag is false");
            }
        }
Exemplo n.º 3
0
        public void LockSalesOrderDetailTempTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);

            // Create a record
            var temp1 = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 1);
            var soht  = SalesService.CopySaleToTemp(testCompany, temp1, testUser, false);
            var sodtl = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, soht.Id, 0);
            var model = sodtl.Items.First();

            // Get the current Lock
            string lockGuid = SalesService.LockSalesOrderDetailTemp(model);

            Assert.IsTrue(!string.IsNullOrEmpty(lockGuid), "Error: Lock record was not found");

            // Simulate another user updating the record
            var otherUser = GetTestUser();
            var error     = SalesService.InsertOrUpdateSalesOrderDetailTemp(model, otherUser, lockGuid);

            Assert.IsTrue(!error.IsError, error.Message);

            // Now get the first user to update the record
            error = SalesService.InsertOrUpdateSalesOrderDetailTemp(model, testUser, lockGuid);
            Assert.IsTrue(error.IsError, "Error: The lock should have caused an error as it has changed");

            // Try to update with the new lock
            lockGuid = SalesService.LockSalesOrderDetailTemp(model);
            error    = SalesService.InsertOrUpdateSalesOrderDetailTemp(model, testUser, lockGuid);
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");
        }
Exemplo n.º 4
0
        public void ShouldThrowExceptionIfGetBlockedBalance()
        {
            // Arrange
            int testClientId = 65;

            this.balanceTableRepository.SearchBalanceByClientId(Arg.Is(testClientId)).Returns(new BalanceEntity()
            {
                Id     = 65,
                Client = new ClientEntity()
                {
                    Id = testClientId
                },
                Amount = 10000.00M,
                Status = false
            });
            SalesService salesService = new SalesService(
                this.operationTableRepository,
                this.balanceTableRepository,
                this.blockedMoneyTableRepository,
                this.sharesNumberTableRepository,
                this.blockedSharesNumberTableRepository);

            // Act
            var balance = salesService.SearchBalanceByClientId(testClientId);

            // Assert
        }
Exemplo n.º 5
0
        public void ShouldSearchSharesNumberForBuy()
        {
            // Arrange
            int shareId   = 55;
            int reqNumber = 5;

            sharesNumberTableRepository.SearchSharesNumberForBuy(Arg.Is(shareId), Arg.Is(reqNumber)).Returns(new SharesNumberEntity()
            {
                Id    = 3,
                Share = new ShareEntity()
                {
                    Id = shareId
                },
                Number = reqNumber + 1
            });
            SalesService salesService = new SalesService(
                this.operationTableRepository,
                this.balanceTableRepository,
                this.blockedMoneyTableRepository,
                this.sharesNumberTableRepository,
                this.blockedSharesNumberTableRepository);

            // Act
            var sharesNumberResult = salesService.SearchSharesNumberForBuy(shareId, reqNumber);

            // Assert
            this.sharesNumberTableRepository.Received(1).SearchSharesNumberForBuy(shareId, reqNumber);
            if (sharesNumberResult.Share.Id != shareId ||
                sharesNumberResult.Number < reqNumber)
            {
                throw new ArgumentException("ShareId or Number in founded shares number is wrong");
            }
        }
Exemplo n.º 6
0
        void prepareEditModel(EditSalesOrderHeaderTempViewModel model, int id)
        {
            var soht = SalesService.FindSalesOrderHeaderTempModel(id, CurrentCompany, false);

            PrepareViewModel(model, EvolutionResources.bnrAddEditSale + " - " + EvolutionResources.lblOrderNumber + ": " + model.SaleTemp.OrderNumber.ToString(), id, MakeMenuOptionFlags(0, 0, 0, soht.OriginalRowId) + MenuOptionFlag.RequiresNewSale);
            model.ParentId = id;

            model.LocationList         = LookupService.FindLocationListItemModel(model.CurrentCompany);
            model.ShippingTemplateList = LookupService.FindDocumentTemplatesListItemModel(DocumentTemplateCategory.Invoice);
            model.CountryList          = LookupService.FindCountriesListItemModel();
            model.OrderTypeList        = LookupService.FindLOVItemsListItemModel(model.CurrentCompany, LOVName.OrderType);
            model.BrandCategoryList    = ProductService.FindBrandCategoryListItemModel(model.CurrentCompany);
            model.SOStatusList         = LookupService.FindSalesOrderHeaderStatusListItemModel();
            model.UserList             = MembershipManagementService.FindUserListItemModel();
            model.PaymentTermsList     = LookupService.FindPaymentTermsListItemModel(model.CurrentCompany);
            if (model.SaleTemp.CustomerId != null)
            {
                model.CreditCardList = CustomerService.FindCreditCardsListItemModel(model.CurrentCompany, model.SaleTemp.CustomerId.Value);
            }

            model.FreightCarrierList = LookupService.FindFreightCarriersListItemModel(model.CurrentCompany);
            model.FreightTermList    = LookupService.FindLOVItemsListItemModel(model.CurrentCompany, LOVName.FreightTerm);

            model.MethodSignedList = LookupService.FindMethodSignedListItemModel();
        }
Exemplo n.º 7
0
        public void ShouldChangeBalanceAmount()
        {
            // Arrange
            SalesService salesService = new SalesService(
                this.operationTableRepository,
                this.balanceTableRepository,
                this.blockedMoneyTableRepository,
                this.sharesNumberTableRepository,
                this.blockedSharesNumberTableRepository);
            var testBalance = new BalanceEntity()
            {
                Id     = 10,
                Amount = 30000.00M,
                Client = new ClientEntity()
                {
                    Id = 10
                },
                Status = true
            };
            decimal newAmount = 35000.00M;

            // Act
            bool flag = salesService.ChangeBalance(testBalance, newAmount);

            // Assert
            this.balanceTableRepository.Received(1).ChangeAmount(testBalance.Id, newAmount);
            this.balanceTableRepository.Received(1).SaveChanges();
            if (!flag)
            {
                throw new ArgumentException("The flag is false");
            }
        }
Exemplo n.º 8
0
        public void DeleteSalesOrderHeaderTest()
        {
            // Get a test user
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);

            // Create a purchase
            var model = GetTestSalesOrderHeader(testCompany, testCustomer, testUser);

            // Check that it was written
            var result = db.FindSalesOrderHeader(model.Id);
            SalesOrderHeaderModel test = SalesService.MapToModel(result);

            var excludes = new List <string>();

            excludes.Add("SalesOrderDetails");  // SalesOrderDetail is a list of objects
            excludes.Add("OrderNumberUrl");     // Because it isn't known at test prep
            AreEqual(model, test, excludes);

            // Now delete it
            SalesService.DeleteSalesOrderHeader(model.Id);

            // And check that is was deleted
            result = db.FindSalesOrderHeader(model.Id);
            Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed");
        }
Exemplo n.º 9
0
        private static void RunProxy()
        {
            //string baseAddress = "http://" + Environment.MachineName + ":8000/Service.svc";
            string baseAddress = "http://localhost:52696/SalesService.svc";

            WebHttpBinding webBinding = new WebHttpBinding
            {
                ContentTypeMapper = new RawContentMapper(),
                MaxReceivedMessageSize = 4194304,
                MaxBufferSize = 4194304,
                SendTimeout = TimeSpan.FromMinutes(4)
            };

            EndpointAddress endpoint = new EndpointAddress(baseAddress + "/json");

            using (SalesService proxy = new SalesService(webBinding, endpoint))
            {
                proxy.Endpoint.Behaviors.Add(new WebHttpJsonNetBehavior());

                try
                {
                    var cons = proxy.GetSalesman(0, 5);
                    Console.WriteLine(cons);
                    Console.ReadLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
            }
        }
Exemplo n.º 10
0
        public ActionResult Knockout_jqGridBinding()
        {
            int orderid = 48730;

            SalesService            _salesService = new SalesService();
            EditSalesOrderViewModel viewModel     = new EditSalesOrderViewModel();

            viewModel.IsEdit = true;
            SalesOrderHeader so = _salesService.GetSalesOrder(orderid);

            viewModel.SO           = SalesModelConverter.ConverToModel(so);
            viewModel.OrderDetails = new List <dynamic>();
            foreach (var detail in so.SalesOrderDetails)
            {
                viewModel.OrderDetails.Add(new
                {
                    productId      = detail.ProductID,
                    specialOfferId = detail.SpecialOfferID,
                    price          = detail.UnitPrice,
                    qty            = detail.OrderQty
                });
            }

            return(View(viewModel));
        }
Exemplo n.º 11
0
        public void FindSalesOrderHeadersListModelTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);

            // Create a random number of sales
            List <SalesOrderHeaderModel> sohList = new List <SalesOrderHeaderModel>();
            int numSohs = RandomInt(5, 25);

            for (int i = 0; i < numSohs; i++)
            {
                sohList.Add(GetTestSalesOrderHeader(testCompany, testCustomer, testUser));
            }

            // Check that they are found
            var result   = SalesService.FindSalesOrderHeadersListModel(testCompany.Id, 0, 1, PageSize, "", 0, 0, 0, 0, (int)SalesOrderHeaderStatus.Quote, 0);
            int actual   = result.Items.Count;
            int expected = numSohs;

            Assert.IsTrue(actual == expected, $"Error: {actual} items were returned when {expected} were expected");

            // Now delete them
            foreach (var poh in sohList)
            {
                SalesService.DeleteSalesOrderHeader(poh);
            }

            // Now check that they have disappeared
            result   = SalesService.FindSalesOrderHeadersListModel(testCompany.Id, 0, 1, PageSize, "", 0, 0, 0, 0, (int)SalesOrderHeaderStatus.Quote, 0);
            actual   = result.Items.Count;
            expected = 0;
            Assert.IsTrue(actual == expected, $"Error: {actual} items were returned when {expected} were expected");
        }
Exemplo n.º 12
0
        public void InsertOrUpdateCreditClaimHeaderTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser);

            // Check db before test
            SalesService.CleanCreditClaimTables();
            CreditClaimHeaderListModel cch = SalesService.FindCreditClaimHeaders();

            int expected = 0;
            int actual   = cch.Items.Count();

            Assert.IsTrue(expected == actual, $"Error: {actual} number of items were found when {expected} were expected");

            // Create and test
            var model = getCreditClaimHeader();

            cch = SalesService.FindCreditClaimHeaders();

            expected = 1;
            actual   = cch.Items.Count();
            Assert.IsTrue(expected == actual, $"Error: {actual} number of items were found when {expected} were expected");
            AreEqual(model, cch.Items);

            // Delete and check after test
            SalesService.CleanCreditClaimTables();
            cch = SalesService.FindCreditClaimHeaders();

            expected = 0;
            actual   = cch.Items.Count();
            Assert.IsTrue(expected == actual, $"Error: {actual} number of items were found when {expected} were expected");
        }
Exemplo n.º 13
0
        public void ShouldFillOperationColumns()
        {
            // Arrange
            SalesService salesService = new SalesService(
                this.operationTableRepository,
                this.balanceTableRepository,
                this.blockedMoneyTableRepository,
                this.sharesNumberTableRepository,
                this.blockedSharesNumberTableRepository,
                this.shareTableRepository);
            var testBlockedMoney = new BlockedMoneyEntity()
            {
                Id            = 2,
                CreatedAt     = DateTime.Now,
                ClientBalance = new BalanceEntity()
                {
                    Id = 2
                },
                Operation = new OperationEntity()
                {
                    Id = 1
                },
                Customer = new ClientEntity()
                {
                    Id = 2
                },
                Total = 1000.00M
            };
            var testBlockedSharesNumber = new BlockedSharesNumberEntity()
            {
                Id                 = 2,
                CreatedAt          = DateTime.Now,
                ClientSharesNumber = new SharesNumberEntity()
                {
                    Id = 4
                },
                Operation = new OperationEntity()
                {
                    Id = 1
                },
                Seller = new ClientEntity()
                {
                    Id = 1
                },
                Share = new ShareEntity()
                {
                    Id = 3
                },
                ShareTypeName = "sharename",
                Cost          = 500,
                Number        = 3,
            };

            // Act
            salesService.FillOperationColumns(testBlockedMoney, testBlockedSharesNumber);

            // Assert
            operationTableRepository.Received(1).FillAllColumns(testBlockedMoney, testBlockedSharesNumber, Arg.Any <DateTime>());
            operationTableRepository.Received(1).SaveChanges();
        }
Exemplo n.º 14
0
 public ClientsController(ClientsService clientsService, BalancesService balancesService, SalesService salesService, ReportsService reportsService)
 {
     this.clientsService  = clientsService;
     this.balancesService = balancesService;
     this.salesService    = salesService;
     this.reportsService  = reportsService;
 }
Exemplo n.º 15
0
        public async Task Db_SalesService_Concurrency_AskClient()
        {
            using (ThreadScopedLifestyle.BeginScope(container))
            {
                SalesService service = container.GetInstance <SalesService>();
                service.SetPolicy(DataConflictPolicy.AskClient);

                var article = await service.GetByIdAsync <Article>(this.dataSet.ArticlesIds.ElementAt(3));

                article.Title = "User1 Title 4";

                this.articlesSqlHelper.ModifyTitle(article.Id, "User2 Title 4");

                DataConflictException dce = Assert.ThrowsAsync <DataConflictException>(async() =>
                {
                    await service.ModifyAsync(article);
                });
                Assert.AreEqual(DalErrorType.BaseServiceDataConflictWithAskClientPolicy, dce.errorType);

                Assert.IsInstanceOf(typeof(Article), dce.CurrentValues);
                Assert.IsInstanceOf(typeof(Article), dce.DatabaseValues);

                Article currentValues  = (Article)dce.CurrentValues;
                Article databaseValues = (Article)dce.DatabaseValues;

                Assert.AreEqual(article.Id, databaseValues.Id);
                Assert.AreEqual("User2 Title 4", databaseValues.Title);

                Assert.AreEqual(article.Id, currentValues.Id);
                Assert.AreEqual("User1 Title 4", currentValues.Title);
            }
        }
Exemplo n.º 16
0
 public SalesController()
 {
     this.saleService      = new SalesService(new EfGenericRepository <Sale>(Data.Context()));
     this.customersService = new CustomersService(new EfGenericRepository <Customer>(Data.Context()));
     this.carsService      = new CarsService(new EfGenericRepository <Car>(Data.Context()),
                                             new PartsService(new EfGenericRepository <Part>(Data.Context())));
 }
Exemplo n.º 17
0
        public ActionResult EditDetails(int id)
        {
            // Called when a user is on one of the sales screens and clicks the sale details option
            var model = new EditSalesOrderHeaderTempViewModel();

            // Use the data in the temp tables
            var saleTemp = SalesService.FindSalesOrderHeaderTempModel(id, CurrentCompany, true);

            saleTemp.UserId = CurrentUser.Id;

            model.SaleTemp = saleTemp;
            prepareEditModel(model, id);

            var sale = SalesService.FindSalesOrderHeaderModel(saleTemp.OriginalRowId, CurrentCompany, true);

            // If any of the items on the order are partially or fully completed, then we
            // disable adding and editing of items.
            // The ids of SalesOrderLineStatus' are the same as the enums.
            var items = SalesService.FindSalesOrderDetailTempsListModel(CurrentCompany.Id, saleTemp.Id, 0);

            foreach (var item in items.Items)
            {
                if (item.LineStatusId == (int)SalesOrderLineStatus.SentForPicking ||
                    item.LineStatusId == (int)SalesOrderLineStatus.Complete)
                {
                    model.PartiallyComplete = true;
                    break;
                }
            }

            model.LGS  = SalesService.LockSalesOrderHeader(sale);
            model.LGST = SalesService.LockSalesOrderHeaderTemp(model.SaleTemp);

            return(View("Edit", model));
        }
Exemplo n.º 18
0
        public void CreatePickDocumentRetailPdfTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser);
            var testCustomer = GetTestCustomer(testCompany, testUser);
            var testCustomerAdditionalInfo = CustomerService.FindCustomerAdditionalInfoModel(testCustomer.Id, testCompany);

            testCustomerAdditionalInfo.ShippingTemplateId = LookupService.FindDocumentTemplateModel(DocumentTemplateCategory.Pickslip, DocumentTemplateType.PackingSlipRetail).Id;
            var error = CustomerService.InsertOrUpdateCustomerAdditionalInfo(testCustomerAdditionalInfo, testUser, CustomerService.LockCustomer(testCustomer));

            Assert.IsTrue(!error.IsError, error.Message);

            var testCreditCard       = GetTestCreditCard(testCompany, testCustomer);
            var testSalesOrderHeader = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 41);
            var location             = LookupService.FindLocationModel(testCompany.DefaultLocationID.Value);

            CreateTestTransfers(testCompany, testUser);

            var testFolder   = Path.GetTempPath() + RandomString();
            var transferName = "Test Transfer:Send-" + FileTransferDataType.WarehousePick;
            var sendConfig   = DataTransferService.FindDataTransferConfigurationModel(transferName);

            testSalesOrderHeader.NextActionId     = LookupService.FindSaleNextActionId(Enumerations.SaleNextAction.ShipSomething);
            testSalesOrderHeader.FreightCarrierId = LookupService.FindFreightCarriersListModel(testCompany.Id).Items.FirstOrDefault().Id;
            testSalesOrderHeader.CreditCardId     = testCreditCard.Id;
            error = SalesService.InsertOrUpdateSalesOrderHeader(testSalesOrderHeader, testUser, SalesService.LockSalesOrderHeader(testSalesOrderHeader));
            Assert.IsTrue(!error.IsError, error.Message);

            error = SalesService.CreatePicks(testCompany, testUser, testSalesOrderHeader.Id.ToString(), false);
            Assert.IsTrue(!error.IsError, error.Message);
        }
Exemplo n.º 19
0
 public ActionResult GetSalesOrderDetailTemps(int index, int parentId, int pageNo, int pageSize, string search,
                                              string sortColumn, int sortOrder)
 {
     return(Json(SalesService.FindSalesOrderDetailTempsListModel(CurrentCompany.Id, parentId, index, pageNo, pageSize, search,
                                                                 sortColumn, (SortOrder)sortOrder),
                 JsonRequestBehavior.AllowGet));
 }
Exemplo n.º 20
0
        public ActionResult SaleDirection()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new SalesService(userId);

            return(View());
        }
Exemplo n.º 21
0
        public void ShouldSearchBalanceByClientId()
        {
            // Arrange
            int testClientId = 60;

            this.balanceTableRepository.SearchBalanceByClientId(Arg.Is(testClientId)).Returns(new BalanceEntity()
            {
                Id     = 61,
                Client = new ClientEntity()
                {
                    Id = testClientId
                },
                Amount = 10000.00M,
                Status = true
            });
            SalesService salesService = new SalesService(
                this.operationTableRepository,
                this.balanceTableRepository,
                this.blockedMoneyTableRepository,
                this.sharesNumberTableRepository,
                this.blockedSharesNumberTableRepository);

            // Act
            var balance = salesService.SearchBalanceByClientId(testClientId);

            // Assert
            this.balanceTableRepository.Received(1).SearchBalanceByClientId(testClientId);
            if (balance.Client.Id != testClientId)
            {
                throw new ArgumentException("Client Id in balance is wrong!");
            }
        }
Exemplo n.º 22
0
        public async Task <IHttpActionResult> AddSales(SalesModel sales)
        {
            if (sales == null)
            {
                return(BadRequest("Please provide valid inputs!"));
            }

            CommonResponse validatedResponse = await AuthService.ValidateUserAndToken();

            if (!validatedResponse.IsError)
            {
                if (await SalesService.AddSales(sales))
                {
                    return(Ok("Transaction Successfully Entered!"));
                }
                else
                {
                    return(BadRequest("Transaction Cannot be Processed!"));
                }
            }
            else
            {
                return(Unauthorized());
            }
        }//end of add
Exemplo n.º 23
0
        public void ShouldCreateEmptyOperation()
        {
            // Arrange
            SalesService salesService = new SalesService(
                this.operationTableRepository,
                this.balanceTableRepository,
                this.blockedMoneyTableRepository,
                this.sharesNumberTableRepository,
                this.blockedSharesNumberTableRepository);

            // Act
            var operation = salesService.CreateOperation();

            // Assert
            this.operationTableRepository.Received(1).Add(Arg.Is <OperationEntity>(
                                                              o => o.Id == operation.Id &&
                                                              o.Customer == null &&
                                                              o.Seller == null &&
                                                              o.Share == null &&
                                                              o.ShareTypeName == null &&
                                                              o.Cost == 1 &&
                                                              o.Number == 1 &&
                                                              o.Total == 1));
            this.operationTableRepository.Received(1).SaveChanges();
        }
Exemplo n.º 24
0
        public async Task <IHttpActionResult> UpdateSales(SalesModel sales)
        {
            if (sales == null)
            {
                return(BadRequest("Please provide valid inputs!"));
            }

            CommonResponse validatedResponse = await AuthService.ValidateUserAndToken();

            if (!validatedResponse.IsError)
            {
                if (await SalesService.SalesExist(sales))
                {
                    if (await SalesService.UpdateSales(sales))
                    {
                        return(Ok("Transaction Updated Successfully!"));
                    }
                    else
                    {
                        return(BadRequest("Failed to Update the Transaction!"));
                    }
                }
                else
                {
                    return(BadRequest("No Such Transaction Exisits!"));
                }
            }
            else
            {
                return(Unauthorized());
            }
        }//end of update
Exemplo n.º 25
0
        public void ShouldCreateSharesNumberForAdditionIfCantSearch()
        {
            // Arrange
            ShareEntity share = new ShareEntity()
            {
                Id = 55
            };
            ClientEntity client = new ClientEntity()
            {
                Id = 3
            };
            SharesNumberEntity nullSharesNumber = null;

            sharesNumberTableRepository.SearchSharesNumberForAddition(Arg.Is(client.Id), Arg.Is(share.Id)).Returns(nullSharesNumber);
            SalesService salesService = new SalesService(
                this.operationTableRepository,
                this.balanceTableRepository,
                this.blockedMoneyTableRepository,
                this.sharesNumberTableRepository,
                this.blockedSharesNumberTableRepository);

            // Act
            var sharesNumberResult = salesService.SearchOrCreateSharesNumberForAddition(client, share);

            // Assert
            this.sharesNumberTableRepository.Received(1).SearchSharesNumberForAddition(client.Id, share.Id);
            this.sharesNumberTableRepository.Received(1).Add(Arg.Any <SharesNumberEntity>());
            this.sharesNumberTableRepository.Received(1).SaveChanges();
        }
        private SalesService CreateSalesService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new SalesService(userId);

            return(service);
        }
Exemplo n.º 27
0
        public void ShouldThrowExceptionIfShareTypeStatusIsFalse()
        {
            SalesService salesService = new SalesService(
                this.operationTableRepository,
                this.balanceTableRepository,
                this.blockedMoneyTableRepository,
                this.sharesNumberTableRepository,
                this.blockedSharesNumberTableRepository);
            var share = new ShareEntity()
            {
                Id          = 3,
                CompanyName = "testCompany",
                CreatedAt   = DateTime.Now,
                Type        = new ShareTypeEntity()
                {
                    Id     = 5,
                    Cost   = 1000.0M,
                    Name   = "typename",
                    Status = false
                },
                Status = true
            };

            // Act
            salesService.CheckShareAndShareTypeStatuses(share);

            // Assert
        }
Exemplo n.º 28
0
        public ActionResult Add()
        {
            // Called when the user clicks 'Create' to create a new sale
            var editModel = new EditSalesOrderHeaderTempViewModel();

            var sale = SalesService.FindSalesOrderHeaderModel(0, CurrentCompany, true);

            sale.OrderDate       = DateTimeOffset.Now;
            sale.SalespersonId   = CurrentUser.Id;
            sale.BrandCategoryId = CurrentUser.DefaultBrandCategoryId;
            var freightCarrier = LookupService.FindFreightCarriersListItemModel(CurrentCompany)
                                 .Where(fc => fc.Text.ToLower() == "unspecified")
                                 .FirstOrDefault();

            if (freightCarrier != null)
            {
                sale.FreightCarrierId = Convert.ToInt32(freightCarrier.Id);
            }
            sale.ShipCountryId = CurrentCompany.DefaultCountryID;
            sale.NextActionId  = LookupService.FindSaleNextActionId(SaleNextAction.None);

            // Copy the order into temp tables for editing
            editModel.SaleTemp = SalesService.CopySaleToTemp(CurrentCompany, sale, CurrentUser, false);

            return(EditDetails(editModel.SaleTemp.Id));
        }
Exemplo n.º 29
0
        public void DeleteSalesOrderDetailTempTest()
        {
            // Get a test user
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser, true);
            var testCustomer = GetTestCustomer(testCompany, testUser);
            var testSale     = GetTestSalesOrderHeader(testCompany, testCustomer, testUser, 1);

            var sohtModel = SalesService.CopySaleToTemp(testCompany, testSale, testUser, false);
            var model     = SalesService.FindSalesOrderDetailTempsListModel(testCompany.Id, sohtModel.Id, 0, 1, PageSize, "");

            // Create a record
            var newItem = createSalesOrderDetailTemp(sohtModel, testCompany, testCustomer, testUser, model.Items[0].ProductId.Value);

            var error = SalesService.InsertOrUpdateSalesOrderDetailTemp(newItem, testUser, "");

            Assert.IsTrue(!error.IsError, error.Message);

            // Check that it was written
            var result = db.FindSalesOrderDetailTemp(newItem.Id);
            var test   = SalesService.MapToModel(result);

            AreEqual(model, test);

            // Now delete it
            SalesService.DeleteSalesOrderDetailTemp(newItem.Id);

            // And check that is was deleted
            result = db.FindSalesOrderDetailTemp(newItem.Id);
            Assert.IsTrue(result == null, "Error: A non-NULL value was returned when a NULL value was expected - record delete failed");
        }
Exemplo n.º 30
0
        public ActionResult Edit(int id)
        {
            // Called when a user clicks to edit a sale
            var model = new EditSalesOrderHeaderTempViewModel();

            var sale = SalesService.FindSalesOrderHeaderModel(id, CurrentCompany, true);

            // Copy the order into temp tables for editing
            model.SaleTemp = SalesService.CopySaleToTemp(CurrentCompany, sale, CurrentUser, false);
            prepareEditModel(model, model.SaleTemp.Id);

            // If any of the items on the order are partially or fully completed, then we
            // disable ading and editing of items.
            // The ids of SalesOrderLineStatus' are the same as the enums.
            var items = SalesService.FindSalesOrderDetailTempsListModel(CurrentCompany.Id, model.SaleTemp.Id, 0);

            foreach (var item in items.Items)
            {
                if (item.LineStatusId == (int)SalesOrderLineStatus.SentForPicking ||
                    item.LineStatusId == (int)SalesOrderLineStatus.Complete)
                {
                    model.PartiallyComplete = true;
                    break;
                }
            }

            model.LGS  = SalesService.LockSalesOrderHeader(sale);
            model.LGST = SalesService.LockSalesOrderHeaderTemp(model.SaleTemp);

            return(View("Edit", model));
        }
Exemplo n.º 31
0
 //Search Entities
 public async Task <IEnumerable <Sales> > SearchSales(List <string> lst, List <string> includeLst = null)
 {
     using (var ctx = new SalesService())
     {
         return(await ctx.GetEntryDataByExpressionLst(lst, includeLst).ConfigureAwait(false));
     }
 }
Exemplo n.º 32
0
        private void RunJsonProxy()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service.svc";

            WebHttpBinding webBinding = new WebHttpBinding
            {
                ContentTypeMapper = new RawContentMapper(),
                MaxReceivedMessageSize = 4194304,
                MaxBufferSize = 4194304,
                SendTimeout = TimeSpan.FromMinutes(4)
            };

            EndpointAddress endpoint = new EndpointAddress(baseAddress + "/json");

            using (SalesService proxy = new SalesService(webBinding, endpoint))
            {
                proxy.Endpoint.Behaviors.Add(new WebHttpJsonNetBehavior());

                try
                {
                    Agency ag = proxy.GetAgency(1);
                    Console.WriteLine(ag);
                    Console.WriteLine();

                    Salesman cons = proxy.GetSalesman(1);
                    Console.WriteLine(cons);
                    Console.WriteLine();

                    Salesman res = proxy.GetFirstSalesman(0, 10);
                    Console.WriteLine(res);
                    Console.WriteLine();

                    IEnumerable<Salesman> conss = proxy.GetPagedSalesman(0, 2);
                    Console.WriteLine(conss);
                    Console.WriteLine();

                    IEnumerable<TradeContract> ctr = proxy.GetPagedContract(0, 10);
                    Console.WriteLine(ctr);
                    Console.WriteLine();

                    var sal = proxy.UpdateCode(new Salesman(true) {Name = "Manuel", Surname = "Lara"}, 150);
                    Console.WriteLine(sal);
                    Console.WriteLine();

                    var sal2 = proxy.UpdateCode(null, 200);
                    Console.WriteLine("sal2 value:{0}", sal2);
                    Console.WriteLine();

                    IList<TradeContract> ctrs = new List<TradeContract>();
                    ctrs.Add(new CarContract{ Price = 10000, Description = "price car"});
                    ctrs.Add(new HomeContract{ Price = 250000, Description = "price home", Town = "sex city"});
                    var col = proxy.VerifyContracts(ctrs);
                    Console.WriteLine(col);
                    Console.WriteLine();

                    var col2 = proxy.VerifyContracts(null);
                    Console.WriteLine("col2 value: {0}", col2);
                    Console.WriteLine();

                    proxy.SaveCode(new CarContract{ Description = "my car", Price = 25000}, 200);
                    Console.WriteLine("TradeContract saved");
                    Console.WriteLine();

                    TradeContract contract = proxy.GetContract(1);
                    Console.WriteLine("TradeContract value: {0}", contract.Owner);
                    Console.WriteLine();

                    Console.WriteLine("Press <ENTER> to terminate client.");
                    Console.ReadLine();
                }
                catch (Exception ex)
                {

                    Console.WriteLine(ex.Message);

                    Console.WriteLine("Inner message:");
                    Console.WriteLine(ex.InnerException == null ? string.Empty : ex.InnerException.Message);
                    Console.WriteLine();

                    Console.ReadLine();
                }
            }
        }