public Response<Order> EditOrder(Order orderToEdit, DateTime orderDate)
        {
            var response = new Response<Order>();

            orderToEdit = CompleteOrder(orderToEdit);

            response.Data = orderToEdit;

            try
            {
                _myOrderRepository.EditOrder(orderToEdit,orderDate);

                response.Success = true;
                response.Message = "Edit successful. Reference Order Number " + orderToEdit.OrderNumber + ".";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;

                try
                {
                    var repo = new LogRepository();
                    repo.WriteLog(ex.Message);
                }
                catch
                {
                    response.Message += "\nCould not write to log file.";
                }
            }

            return response;
        }
        public Response<int> DeleteOrder(int orderNumber, DateTime orderDate)
        {
            var response = new Response<int>();
            try
            {
                _myOrderRepository.DeleteOrder(orderNumber, orderDate);

                response.Data = orderNumber;
                response.Success = true;
                response.Message = "Order " + orderNumber + " deleted.";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;

                try
                {
                    var repo = new LogRepository();
                    repo.WriteLog(ex.Message);
                }
                catch
                {
                    response.Message += "\nCould not write to log file.";
                }
            }

            return response;
        }
        public Response<bool> IsValidProduct(string productType)
        {
            List<Product> allProducts;
            var response = new Response<bool>();

            try
            {
                allProducts = _myProductRepository.ListAll();
                response.Data = allProducts.Any(s => s.ProductType == productType);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                try
                {
                    var repo = new LogRepository();
                    repo.WriteLog(ex.Message);
                }
                catch
                {
                    response.Message += "Could not write to log file.";
                }
            }

            return response;
        }
        public Response<decimal> GetMaterialPerSquareFoot(string productType)
        {
            List<Product> allProducts;
            var response = new Response<decimal>();

            try
            {
                allProducts = _myProductRepository.ListAll();
                response.Data = allProducts.First(s => s.ProductType == productType).CostPerSquareFoot;
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                try
                {
                    var repo = new LogRepository();
                    repo.WriteLog(ex.Message);
                }
                catch
                {
                    response.Message += "\nCould not write to log file.";
                }
            }

            return response;
        }
 public AddOrderWF()
 {
     this._exportDto = new OrderDto();
     this._submit = new OrderManager();
     this._response = new Response<RepoReceipt>();
     this._util = new WorkflowUtilities();
 }
        public Response Update(Response response)
        {
            this.responses.Update(response);
            this.responses.SaveChanges();

            return response;
        }
        public Response Add(Response response)
        {
            this.responses.Add(response);
            this.responses.SaveChanges();

            return response;
        }
        public Response<bool> IsValidState(string stateAbbreviation)
        {
            List<StateTaxInfo> allTaxes;
            var response = new Response<bool>();

            try
            {
                allTaxes = _myStateTaxInfoRepository.ListAll();
                response.Data = allTaxes.Any(s => s.StateAbbreviation == stateAbbreviation);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                try
                {
                    var repo = new LogRepository();
                    repo.WriteLog(ex.Message);
                }
                catch
                {
                    response.Message += "\nCould not write to log file.";
                }
            }

            return response;
        }
        public Response<RepoReceipt> EditOrder(OrderDto inDto)
        {
            var result = new Response<RepoReceipt>();

            result.Data = _repo.EditOrder(inDto);

            return ProcessResult(result, "Edit Successful", "Edit Failed");
        }
        public Response<RepoReceipt> DeleteOrder(DateTime inDate, int inID)
        {
            var result = new Response<RepoReceipt>();

            result.Data = _repo.DeleteOrder(inDate, inID);

            return ProcessResult(result, "Delete Successful", "Delete Failed");
        }
        public void Execute()
        {
            string userInput = "";

            do
            {
                _util.DrawFormPriorToSubmissionResponse(_exportDto);

                _exportDto = _util.GetCustomerName();
                if (_exportDto.CustomerName == "Q")
                    break;
                _util.DrawFormPriorToSubmissionResponse(_exportDto);

                _exportDto = _util.GetSquareFootage();
                if (_exportDto.CustomerName == "Q")
                    break;
                _util.DrawFormPriorToSubmissionResponse(_exportDto);

                _exportDto = _util.GetStateAbbv();
                if (_exportDto.CustomerName == "Q")
                    break;
                _util.DrawFormPriorToSubmissionResponse(_exportDto);

                _exportDto = _util.GetProductType();
                if (_exportDto.CustomerName == "Q")
                    break;
                _util.DrawFormPriorToSubmissionResponse(_exportDto);

                _exportDto.Date = _util.GetAddDate();
                if (_exportDto.Date == DateTime.MaxValue)
                    break;
                _util.DrawFormPriorToSubmissionResponse(_exportDto);

                do
                {
                    Console.WriteLine("\nPress 'S' to submit, 'R' to retry, or 'Q' to quit...");
                    userInput = Console.ReadLine().ToLower();
                } while (userInput != "r" && userInput != "s" && userInput != "q");

                switch (userInput)
                {
                    case "s":
                        _response = _submit.AddOrder(_exportDto);
                        _util.DrawFormFullyPopulatedAfterOrderAdded(_exportDto, _response);
                        Console.WriteLine(_response.Message);
                        Console.ReadKey();
                        break;
                    case "q":
                        break;
                    case "r":
                        _exportDto = new OrderDto();
                        break;
                }
            } while (userInput == "r");
        }
        public void OrderEditSucessful()
        {
            TestSetup();
            _dto.CustomerName = "TestEd";
            Response<RepoReceipt> r = new Response<RepoReceipt>();

            r = _mgr.EditOrder(_dto);

            Assert.IsTrue(r.Success);
            Assert.AreEqual(1, r.Data.ID);
            TestTearDown();
        }
        public void OrderDeleteNotSucessful()
        {
            TestSetup();
            var date = new DateTime(1901, 1, 26);
            int id = 351;
            Response<RepoReceipt> r = new Response<RepoReceipt>();

            r = _mgr.DeleteOrder(date, id);

            Assert.IsTrue(!r.Success);
            Assert.AreEqual("Cannot delete - Order not found...", r.Data.Message);
            TestTearDown();
        }
        public void OrderDeleteSucessful()
        {
            TestSetup();

            var date = new DateTime(1901, 1, 1);

            int id = 1;

            Response<RepoReceipt> r = new Response<RepoReceipt>();

            r = _mgr.DeleteOrder(date, id);

            Assert.IsTrue(r.Success);
            Assert.AreEqual("Order deleted.", r.Data.Message);
        }
        public Response<decimal> GetLaborPerSquareFoot(string productType)
        {
            List<Product> allProducts;
            var response = new Response<decimal>();

            try
            {
                allProducts = _myProductRepository.ListAll();
                response.Data = allProducts.First(s => s.ProductType == productType).LaborCostPerSquareFoot;
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return response;
        }
        public Response<decimal> GetRate(string stateAbbreviation)
        {
            List<StateTaxInfo> allTaxes;
            var response = new Response<decimal>();

            try
            {
                allTaxes = _myStateTaxInfoRepository.ListAll();
                response.Data = allTaxes.First(s => s.StateAbbreviation == stateAbbreviation).TaxRate;
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return response;
        }
        public Response<ProductDto> ValidateProduct(object inProduct)
        {
            var result = new Response<ProductDto>();
            var prodList = _repo.ReadAllProducts();
            bool checkString = inProduct is string;

            if (!checkString)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                result.Message = "Please enter a valid product...";
                Console.ResetColor();
                result.Success = false;
                return result;
            }

            string productsString = prodList.Aggregate("", (current, p) => current + (p.ProductType + "  "));

            try
            {
                foreach (var p in prodList)
                {
                    if (p.ProductType == inProduct.ToString())
                    {
                        result.Success = true;
                        result.Message = "OK";
                        result.Data.ProductType = p.ProductType;
                        result.Data.MatPsf = p.MatPsf;
                        result.Data.LbrPsf = p.LbrPsf;
                        break;
                    }
                    result.Success = false;
                    Console.ForegroundColor = ConsoleColor.Red;
                    result.Message = "Product not found... Please choose from the following products:\n" + productsString;
                    Console.ResetColor();
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = "He's DEAD Jim! - {0}" + ex.Message;
            }

            return result;
        }
        public void OrderAddSucessful()
        {
            // arr
            _dto.CustomerName = "Test";
            _dto.State = "MI";
            _dto.TaxRate = 10M;
            _dto.ProdType = "Marble";
            _dto.FloorArea = 100M;
            _dto.MaterialsPsF = 1.00M;
            _dto.LaborPsF = 1.00M;
            _dto.Date = new DateTime(1901, 1, 1);
            Response<RepoReceipt> r = new Response<RepoReceipt>();
            // act
            r = _mgr.AddOrder(_dto);
            // assert
            Assert.IsTrue(r.Success);
            Assert.AreEqual(_testDate.Date.Date, r.Data.Date.Date);

            TestTearDown();
        }
        public void DrawFormFullyPopulatedAfterOrderAdded(OrderDto dto, Response<RepoReceipt> response)
        {
            var date = dto.Date.ToShortDateString();

            Console.Clear();
            Console.WriteLine("                     <FoS Order Systems>");
            Console.WriteLine();
            Console.WriteLine("=================================================================");
            Console.WriteLine(format, dto.CustomerName);
            Console.WriteLine();
            Console.WriteLine(format1, dto.State, response.Data.ID);
            Console.WriteLine(format2, dto.ProdType, date);
            Console.WriteLine(format3, dto.FloorArea, dto.TotalMaterials);
            Console.WriteLine(format4, dto.MaterialsPsF, dto.TotalLabor);
            Console.WriteLine(format5, dto.LaborPsF, dto.TotalCostPreTax);
            Console.WriteLine(format6, dto.TaxRate, dto.TotalTax);
            Console.WriteLine(format7, dto.TotalCost);
            Console.WriteLine("=================================================================");
            Console.WriteLine();
        }
        public Response<DashBoardDto> GetDasboard()
        {
            var result = new Response<DashBoardDto>();

            _dto.DashboardAsOfDate = DateTime.Now;
            _dto.OrderGrandTotal = GetOrderGrandTotal();
            _dto.TotalSFOnOrder = GetTotalSfOnOrder();
            _dto.MatGrandTotal = GetMaterialGrandTotal();
            _dto.LaborGrandTotal = GetLaborGrandTotal();
            _dto.BestState = GetBestState();
            _dto.BestStateTotal = _bestStateGross;
            _dto.BestCustomer = GetBestCustomer();
            _dto.BestCustomerTotal = _bestCustomerGross;
            _dto.BestProduct = GetBestProduct();
            _dto.BestProductTotal = _bestProductGross;

            result.Data = _dto;

            return result;
        }
        public bool AddFavorite(int userID, int dishID)
        {
            Response<Favorite> response;
            FavoriteDB favoriteDB = new FavoriteDB();
            bool exists = favoriteDB.Exists(userID, dishID);

            if(!exists)
            {
                Favorite favorite = new Favorite();
                favorite.DishID = dishID;
                favorite.UserID = userID;

                response = favorite.Create();

            }
            else
            {
                //if the favorite does exists
                response = new Response<Favorite>();
            }

            return response.Success;
        }
Exemple #22
0
 public void Handle(Response r)
 {
     if (r.RequestType == RequestEnum.ListOfDrives)
       {
     form.drives = JArray.FromObject(r.Data).ToObject<List<DriveData>>();
     form.Invoke((MethodInvoker)delegate
     {
       form.UpdatePanes();
     });
       }
       else if (r.RequestType == RequestEnum.OpenFolder)
       {
     FolderData data = ((JObject)r.Data).ToObject<FolderData>();
     form.Files = data.Files;
     form.Folders = data.Folders;
     form.loading = false;
       }
       else if (r.RequestType == RequestEnum.CopyData)
       {
     Debug.WriteLine("Client Recieved Copy Complete!");
     form.Invoke((MethodInvoker)delegate
     {
       form.UpdatePanes();
     });
     form.loading = false;
       }
       else if (r.RequestType == RequestEnum.CopyUpdate)
       {
     CopyDataUpdate data = ((JObject)r.Data).ToObject<CopyDataUpdate>();
     //Debug.WriteLine("Job Progress: " + (data.jobProgress * 100.0 / data.jobTotal * 1.0) + " - Copy Progress: " + data.Progress);
     form.Invoke((MethodInvoker)delegate
     {
       Debug.WriteLine("Client Source: " + data.Source);
       form.UpdateProgress(data.Progress, Convert.ToInt32(data.jobProgress * 100.0 / data.jobTotal * 1.0), Path.GetFileName(data.Source));
     });
       }
 }
        public Response<OrderDto> LookUpSingleOrder(DateTime inDate, int inID)
        {
            var result = new Response<OrderDto>();
            List<OrderDto> currListOfOrder = ListAllOrders();
            OrderDto orderFound = currListOfOrder.FirstOrDefault(o => o.Date.Date == inDate.Date && o.ID == inID);

            try
            {
                if (orderFound != null)
                {
                    result.Success = true;
                    result.Data = orderFound;
                    result.Message = "Order Lookup Successful.";
                }

                // no match
                else
                {
                    result.Success = false;
                    Console.ForegroundColor = ConsoleColor.Red;
                    result.Message = "Order not found... ";
                    Console.ResetColor();
                }

            }

            catch (Exception ex)
            {
                result.Success = false;
                result.Data.IsFailLoggable = true;
                result.Message = "He's DEAD Jim! - {0}" + ex.Message;
            }

            return result;
        }
        public Response<OrderDto> LookUpSingleOrder(DateTime inDate, int inID)
        {
            var result = new Response<OrderDto>();

            try
            {
                foreach (var o in ListOfOrder)
                {

                    if (o.ID == inID)
                    {
                        result.Data = o;
                        result.Success = true;
                        result.Message = "Order Lookup Successful.";
                        break;
                    }

                    // no match
                    else
                    {
                        result.Success = false;
                        Console.ForegroundColor = ConsoleColor.Red;
                        result.Message = "Order not found... ";
                        Console.ResetColor();
                    }
                }
            }

            catch (Exception ex)
            {
                result.Success = false;
                result.Message = "He's DEAD Jim! - {0}" + ex.Message;
            }

            return result;
        }
 private void TestSetup()
 {
     _dto.CustomerName = "Test";
     _dto.State = "MI";
     _dto.TaxRate = 10M;
     _dto.ProdType = "Marble";
     _dto.FloorArea = 100M;
     _dto.MaterialsPsF = 1.00M;
     _dto.LaborPsF = 1.00M;
     _dto.Date = new DateTime(1901, 1, 1);
     Response<RepoReceipt> r = new Response<RepoReceipt>();
     r = _mgr.AddOrder(_dto);
 }
        public Response<List<Order>> GetAllOrders(DateTime orderDate)
        {
            var response = new Response<List<Order>>();

            try
            {
                var orders = _myOrderRepository.GetAllOrders(orderDate);

                response.Data = orders;

                if (orders.LongCount() == 0)
                {
                    response.Success = false;
                    response.Message = "File not found.";
                }
                else
                {
                    response.Success = true;
                    response.Data = orders;
                    response.Message = "";
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;

                try
                {
                    var repo = new LogRepository();
                    repo.WriteLog(ex.Message);
                }
                catch
                {
                    response.Message += "\nCould not write to log file.";
                }
            }

            return response;
        }
 private void TestTearDown()
 {
     var date = new DateTime(1901, 1, 1);
     int id = 1;
     Response<RepoReceipt> r = new Response<RepoReceipt>();
     r = _mgr.DeleteOrder(date, id);
 }
        public void OrderLookUpNotSucessful()
        {
            TestSetup();
            var date = new DateTime(1905, 3, 31);
            int id = 199935165;
            string idString = id.ToString();
            Response<OrderDto> r = new Response<OrderDto>();

            r = _mgr.LookupSingleOrder(date, id);

            Assert.IsTrue(r.Success == false);
            Assert.AreNotEqual(idString, r.Data.ID);
            TestTearDown();
        }
        public Response<Order> NewOrder(Order orderToAdd)
        {
            var response = new Response<Order>();

            orderToAdd = CompleteOrder(orderToAdd);

            try
            {
                var orders = _myOrderRepository.GetAllOrders(DateTime.Today);

                if (orders.LongCount() > 0)
                    orderToAdd.OrderNumber = orders.Max(o => o.OrderNumber) + 1;
                else
                    orderToAdd.OrderNumber = 1;

                _myOrderRepository.AddOrder(orderToAdd);

                response.Data = orderToAdd;
                response.Success = true;
                response.Message = "Order "+ orderToAdd.OrderNumber + " added.";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;

                try
                {
                    var repo = new LogRepository();
                    repo.WriteLog(ex.Message);
                }
                catch
                {
                    response.Message += "\nCould not write to log file.";
                }
            }

            return response;
        }
        public Response<Order> GetOrder(int orderNum, DateTime orderDate)
        {
            var response = new Response<Order>();

            try
            {
                var order = _myOrderRepository.GetOrder(orderNum, orderDate);

                if (order == null)
                {
                    response.Success = false;
                    response.Message = "Order not found.";
                }
                else
                {
                    response.Success = true;
                    response.Data = order;
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;

                try
                {
                    var repo = new LogRepository();
                    repo.WriteLog(ex.Message);
                }
                catch
                {
                    response.Message += "\nCould not write to log file.";
                }
            }

            return response;
        }