Exemplo n.º 1
0
 public static int CountUserOrders(this HtmlHelper htmlHelper, int userId, int companyId)
 {
     using (OrdersRepository ordersRep = new OrdersRepository(companyId))
     {
         return ordersRep.GetList().Where(x => x.UserId == userId).Count();
     }
 }
Exemplo n.º 2
0
        public ActionResult AjaxPaging()
        {
            var repository = new OrdersRepository();
            ViewBag.ActiveMenuTitle = "AjaxPaging";

            return View("Index", new OrdersAjaxPagingGrid(repository.GetAll(), 1, false));
        }
Exemplo n.º 3
0
 public static int CountUserPendingOrders(this HtmlHelper htmlHelper, int userId, int companyId)
 {
     using (OrdersRepository ordersRep = new OrdersRepository(companyId))
     {
         return ordersRep.GetList().Where(x => x.NextOrderApproverId == userId && x.StatusId != (int)StatusType.PendingOrderCreator).Count();
     }
 }
Exemplo n.º 4
0
        public JsonResult GetOrder(int id)
        {
            var repository = new OrdersRepository();
            Order order = repository.GetById(id);
            if (order == null)
                return Json(new { Status = 0, Message = "Not found" });

            return Json(new { Status = 1, Message = "Ok", Content = RenderPartialViewToString("_OrderInfo", order) });
        }
        public void Get_Next_order_number()
        {
            var repository = new OrdersRepository(
                new MainUnitOfWork(ConfigurationManager.AppSettings["AzureConnectionString"]));

            var result = repository.GetNextOrderNumber();

            Assert.IsNotNull(result);
        }
Exemplo n.º 6
0
 public static int CountPendingExport(this HtmlHelper htmlHelper, int companyId)
 {
     using (OrdersRepository ordersRep = new OrdersRepository(companyId))
     {
         return ordersRep.GetList("Orders_Statuses", "Supplier", "User")
             .Where(x => x.StatusId == (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport)
             .Count();
     }
 }
Exemplo n.º 7
0
 public static int CountPendingInventory(this HtmlHelper htmlHelper, int companyId)
 {
     using (OrdersRepository ordersRep = new OrdersRepository(companyId))
     {
         return ordersRep.GetList("Orders_Statuses", "Supplier", "User")
             .Where(x =>
                 !x.WasAddedToInventory &&
                 x.StatusId > (int)StatusType.InvoiceScannedPendingOrderCreator)
             .Count();
     }
 }
 //
 // GET: /ExportMoveInFile/
 public ActionResult Index()
 {
     using (OrdersRepository ordersRepository = new OrdersRepository(CurrentUser.CompanyId))
     {
         List<Order> toExportOrders = ordersRepository
             .GetList("Orders_Statuses", "Supplier", "User")
             .Where(x => x.CompanyId == CurrentUser.CompanyId && x.StatusId == (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport)
             .ToList();
         return View(toExportOrders);
     }
 }
Exemplo n.º 9
0
        public JsonResult GetOrdersGridRows(int page)
        {
            var repository = new OrdersRepository();
            var grid = new OrdersAjaxPagingGrid(repository.GetAll(), page, true);

            return Json(new
            {
                Html = RenderPartialViewToString("_OrdersGrid", grid),
                HasItems = grid.DisplayingItemsCount >= grid.Pager.PageSize
            }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 10
0
 public TasksController(TaskRepository taskRepository, 
     UserRepository userRepository, OrdersRepository ordersRepository,
     UserResponseHistoryRepository userResponseHistoryRepository, 
     UserService userService,
     BillingService billingService,
     GigbucketDbContext dbContext)
 {
     _taskRepository = taskRepository;
     _userRepository = userRepository;
     _ordersRepository = ordersRepository;
     _userResponseHistoryRepository = userResponseHistoryRepository;
     _userService = userService;
     _billingService = billingService;
     _dbContext = dbContext;
 }
Exemplo n.º 11
0
 public static int CountDelayingOrders(this HtmlHelper htmlHelper, int companyId)
 {
     using (OrdersRepository ordersRep = new OrdersRepository(companyId))
     {
         DateTime CurrentTime = DateTime.Now;
         return ordersRep.GetList("Orders_Statuses", "Supplier", "User")
             .Where(x =>
                 EntityFunctions.DiffHours(x.CreationDate, CurrentTime) >= 48 &&
                 x.StatusId < (int)StatusType.ApprovedPendingInvoice &&
                 x.StatusId != (int)StatusType.Declined &&
                 x.StatusId != (int)StatusType.OrderCancelled
                 )
             .Count();
     }
 }
Exemplo n.º 12
0
        public void AddOrder_should_save_into_database()
        {
            var order = new Order();
            order.MobileNumber = 456789;
            order.StreetAddress = "201 s heuights blvd";
            order.Landmark = "near allen pkwy";
            order.City = "bavdhan";
            order.State = "Maharashtra";
            order.Pincode = 411021;
            order.OrderDate = DateTime.Now;

            var repository = new OrdersRepository(
                new MainUnitOfWork(ConfigurationManager.AppSettings["AzureConnectionString"]));
            repository.SubmitOrder(order);


        }
        public void ItReturnsNotNullModel()
        {
            // Arrange
            AviTradeContext dbContext = new AviTradeContext();
            IItemsRepository itemsRepository = new ItemsRepository(dbContext);
            IAirportsRepository airportsRepository = new AirportsRepository(dbContext);
            IAircraftsRepository aircraftsRepository = new AircraftsRepository(dbContext);
            IContractsRepository contractsRepository = new ContractsRepository(dbContext);
            ITradersRepository tradersRepository = new TradersRepository(dbContext);
            IPeriodsRepository periodsRepository = new PeriodsRepository(dbContext);
            IInvoicesRepository invoicesRepository = new InvoicesRepository(dbContext, periodsRepository);
            ICurrenciesRepository currenciesRepository = new CurrenciesRepository(dbContext);
            IOrdersRepository ordersRepository = new OrdersRepository(dbContext, contractsRepository, airportsRepository, aircraftsRepository, itemsRepository, currenciesRepository, invoicesRepository);
            DataServiceController controller = null; // new DataServiceController(contractsRepository, tradersRepository, ordersRepository, itemsRepository, airportsRepository, aircraftsRepository);

            // Act
            AjaxOrdersViewModel model = controller.BuildAjaxOrdersViewModel(1, 0, "1,2,3,4", DateTime.Now.AddDays(30),
                                                                            true, 0, 20);

            // Assert
            Assert.IsNotNull(model);
        }
Exemplo n.º 14
0
        public ActionResult AddToInventory(int id = 0)
        {
            if (!Authorized(RoleType.InventoryManager)) return Error(Loc.Dic.error_no_permission);

            Order order;
            List<Location> locations = null;
            AddToInventoryModel model = new AddToInventoryModel();

            using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            {
                order = orderRep.GetEntity(id, "Supplier", "Orders_OrderToItem", "Orders_OrderToItem.Orders_Items");
                if (order == null) return Error(Loc.Dic.error_order_not_found);
                if (order.StatusId < (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport) return Error(Loc.Dic.error_order_not_approved);

                locations = locationsRep.GetList().OrderBy(x => x.Name).ToList();
                if (locations == null || locations.Count == 0) return Error(Loc.Dic.error_no_locations_found);
            }

            model.OrderId = order.Id;
            model.OrderItems = order.Orders_OrderToItem.ToList();
            model.LocationsList = new SelectList(locations, "Id", "Name");
            return View(model);
        }
Exemplo n.º 15
0
        public ActionResult InvoiceApproval(string selectedStatus, int orderId = 0)
        {
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);

            Order order;
            int? historyActionId = null;
            using (OrdersRepository ordersRepository = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRepository.GetEntity(orderId);

                if (order == null) return Error(Loc.Dic.error_order_not_found);
                if (order.UserId != CurrentUser.UserId) return Error(Loc.Dic.error_no_permission);

                if (selectedStatus == Loc.Dic.ApproveInvoce)
                {
                    order.StatusId = (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport;
                    order.LastStatusChangeDate = DateTime.Now;
                    historyActionId = (int)HistoryActions.InvoiceApproved;
                }
                if (selectedStatus == Loc.Dic.CancelOrder)
                {
                    order.StatusId = (int)StatusType.OrderCancelled;
                    order.LastStatusChangeDate = DateTime.Now;
                    historyActionId = (int)HistoryActions.Canceled;
                }

                Orders_History orderHistory = new Orders_History();
                using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, order.Id))
                    if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value);

                if (ordersRepository.Update(order) == null) return Error(Loc.Dic.error_database_error);
            }

            return RedirectToAction("MyOrders");
        }
Exemplo n.º 16
0
        public ActionResult Index(int page = FIRST_PAGE, string sortby = DEFAULT_SORT, string order = DEFAULT_DESC_ORDER)
        {
            if (!Authorized(RoleType.OrdersViewer)) return Error(Loc.Dic.error_no_permission);

            IEnumerable<Order> orders;
            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                orders = ordersRep.GetListWithCanceled("Orders_Statuses", "Supplier", "User");

                if (orders == null) return Error(Loc.Dic.error_orders_get_error);

                orders = Pagination(orders, page, sortby, order);

                return View(orders.ToList());
            }
        }
Exemplo n.º 17
0
        public ActionResult Edit(CreateOrderModel model, string itemsString)
        {
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);
            if (!ModelState.IsValid) return Error(Loc.Dic.error_invalid_form);

            // Initializing needed temporary variables
            bool wasReturnedToCreator;
            bool allowExeeding = true;
            List<Orders_OrderToAllocation> AllocationsToCreate = new List<Orders_OrderToAllocation>();

            Order orderFromDatabase;
            List<Orders_OrderToItem> itemsFromEditForm = new List<Orders_OrderToItem>();
            List<Orders_OrderToItem> itemsToDelete = new List<Orders_OrderToItem>();
            List<Orders_OrderToItem> itemsToCreate = new List<Orders_OrderToItem>();
            List<Orders_OrderToItem> itemsToUpdate = new List<Orders_OrderToItem>();

            decimal totalOrderPrice;
            decimal totalAllocation;
            List<Budgets_Allocations> orderAllocations = new List<Budgets_Allocations>();

            using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                orderFromDatabase = orderRep.GetEntity(model.Order.Id, "Supplier", "Orders_OrderToItem", "Orders_OrderToAllocation", "Users_ApprovalRoutes.Users_ApprovalStep");
            }

            if (orderFromDatabase == null) return Error(Loc.Dic.error_order_not_found);
            if (orderFromDatabase.UserId != CurrentUser.UserId) return Error(Loc.Dic.error_no_permission);

            if (orderFromDatabase.StatusId != (int)StatusType.Pending && orderFromDatabase.StatusId != (int)StatusType.PendingOrderCreator) return Error(Loc.Dic.error_order_edit_after_approval);
            wasReturnedToCreator = orderFromDatabase.StatusId == (int)StatusType.PendingOrderCreator;

            itemsFromEditForm = ItemsFromString(itemsString, model.Order.Id);
            if (itemsFromEditForm == null) return Error(Loc.Dic.error_invalid_form);
            if (itemsFromEditForm.Count == 0) return Error(Loc.Dic.error_order_has_no_items);
            if (itemsFromEditForm.Count == 0) return Error(Loc.Dic.error_order_has_no_items);

            totalOrderPrice = (decimal.Floor(itemsFromEditForm.Sum(x => x.SingleItemPrice * x.Quantity) * 1000) / 1000);

            if (model.Allocations == null || model.Allocations.Where(x => x.IsActive).Count() == 0) return Error(Loc.Dic.error_invalid_form);
            model.Allocations = model.Allocations.Where(x => x.IsActive).ToList();
            totalAllocation = (decimal.Floor(model.Allocations.Sum(x => x.Amount) * 1000) / 1000);

            if (totalOrderPrice != totalAllocation) return Error(Loc.Dic.error_order_insufficient_allocation);

            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
            using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
            {
                Budget currentBudget = budgetsRep.GetList().SingleOrDefault(x => x.CompanyId == CurrentUser.CompanyId && x.IsActive);
                if (currentBudget == null) return Error(Loc.Dic.error_database_error);
                model.Order.BudgetId = currentBudget.Id;

                int[] orderAllocationsIds = model.Allocations.Select(x => x.AllocationId).Distinct().ToArray();
                var allocationsData = allocationsRep.GetAllocationsData(orderAllocationsIds, StatusType.Pending);
                bool IsValidAllocations =
                    (allocationsData.Count == orderAllocationsIds.Length) &&
                    model.Allocations.All(x => (x.MonthId == null || (x.MonthId >= 1 && x.MonthId <= 12)) && x.Amount > 0);
                if (!IsValidAllocations) return Error(Loc.Dic.error_invalid_form);

                if (model.IsFutureOrder)
                {
                    foreach (var allocationData in allocationsData)
                    {
                        List<OrderAllocation> allocationMonths = model.Allocations.Where(x => x.AllocationId == allocationData.AllocationId).ToList();

                        foreach (var month in allocationMonths)
                        {
                            if (month.MonthId == DateTime.Now.Month)
                            {
                                OrderAllocation currentAllocation = model.Allocations.SingleOrDefault(x => x.AllocationId == allocationData.AllocationId);

                                var newAllocations = allocationsRep.GenerateOrderAllocations(allocationData, currentAllocation.Amount, allowExeeding, DateTime.Now.Month, orderFromDatabase.Id);
                                if (newAllocations == null) return Error(Loc.Dic.error_order_insufficient_allocation);

                                AllocationsToCreate.AddRange(newAllocations);
                            }
                            else
                            {
                                var monthData = allocationData.Months.SingleOrDefault(x => x.MonthId == month.MonthId);
                                if (!allowExeeding && month.Amount > monthData.RemainingAmount) return Error(Loc.Dic.error_order_insufficient_allocation);

                                Orders_OrderToAllocation newAllocation = new Orders_OrderToAllocation()
                                {
                                    AllocationId = allocationData.AllocationId,
                                    MonthId = month.MonthId.Value,
                                    Amount = month.Amount,
                                    OrderId = orderFromDatabase.Id
                                };

                                AllocationsToCreate.Add(newAllocation);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var allocationData in allocationsData)
                    {
                        OrderAllocation currentAllocation = model.Allocations.SingleOrDefault(x => x.AllocationId == allocationData.AllocationId);

                        var newAllocations = allocationsRep.GenerateOrderAllocations(allocationData, currentAllocation.Amount, allowExeeding, DateTime.Now.Month, orderFromDatabase.Id);
                        if (newAllocations == null) return Error(Loc.Dic.error_order_insufficient_allocation);

                        AllocationsToCreate.AddRange(newAllocations);
                    }
                }
            }

            using (OrderToAllocationRepository orderAllocationRep = new OrderToAllocationRepository())
            {
                foreach (var item in orderFromDatabase.Orders_OrderToAllocation)
                {
                    orderAllocationRep.Delete(item.Id);
                }

                foreach (var item in AllocationsToCreate)
                {
                    orderAllocationRep.Create(item);
                }
            }

            foreach (var newItem in itemsFromEditForm)
            {
                Orders_OrderToItem existingItem = orderFromDatabase.Orders_OrderToItem.SingleOrDefault(x => x.ItemId == newItem.ItemId);

                if (existingItem != null)
                {
                    if (
                        existingItem.Quantity != newItem.Quantity ||
                        existingItem.SingleItemPrice != newItem.SingleItemPrice
                        )
                    {
                        newItem.Id = existingItem.Id;
                        itemsToUpdate.Add(newItem);
                    }
                }
                else
                {
                    itemsToCreate.Add(newItem);
                }
            }

            foreach (var existingItem in orderFromDatabase.Orders_OrderToItem)
            {
                Orders_OrderToItem newItem = itemsFromEditForm.SingleOrDefault(x => x.ItemId == existingItem.ItemId);

                if (newItem == null)
                {
                    itemsToDelete.Add(existingItem);
                }
            }

            bool noErrors = true;

            using (OrderToItemRepository orderToItemRep = new OrderToItemRepository())
            {
                foreach (var item in itemsToCreate)
                {
                    if (!orderToItemRep.Create(item) && noErrors)
                        noErrors = false;
                }
                foreach (var item in itemsToUpdate)
                {
                    if (orderToItemRep.Update(item) == null && noErrors)
                        noErrors = false;
                }
                foreach (var item in itemsToDelete)
                {
                    if (!orderToItemRep.Delete(item.Id) && noErrors)
                        noErrors = false;
                }

                using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                {
                    if (!CurrentUser.OrdersApprovalRouteId.HasValue)
                    {
                        model.Order.NextOrderApproverId = null;
                        model.Order.StatusId = (int)StatusType.ApprovedPendingInvoice;
                    }
                    else
                    {
                        Users_ApprovalRoutes orderRoute = orderFromDatabase.Users_ApprovalRoutes; //routesRep.GetEntity(CurrentUser.OrdersApprovalRouteId.Value, "Users_ApprovalStep");
                        Users_ApprovalStep firstStep = orderRoute.Users_ApprovalStep.OrderBy(x => x.StepNumber).FirstOrDefault();

                        if (firstStep != null)
                        {
                            model.Order.ApprovalRouteId = orderRoute.Id;
                            model.Order.ApprovalRouteStep = firstStep.StepNumber;
                            model.Order.NextOrderApproverId = firstStep.UserId;
                            model.Order.StatusId = (int)StatusType.Pending;
                        }
                        else
                        {
                            model.Order.ApprovalRouteId = null;
                            model.Order.ApprovalRouteStep = null;
                            model.Order.NextOrderApproverId = null;
                            model.Order.StatusId = (int)StatusType.ApprovedPendingInvoice;
                        }
                    }

                    model.Order.CompanyId = orderFromDatabase.CompanyId;
                    model.Order.CreationDate = orderFromDatabase.CreationDate;
                    model.Order.SupplierId = orderFromDatabase.SupplierId;
                    model.Order.UserId = orderFromDatabase.UserId;
                    model.Order.OrderNumber = orderFromDatabase.OrderNumber;
                    model.Order.InvoiceNumber = orderFromDatabase.InvoiceNumber;
                    model.Order.InvoiceDate = orderFromDatabase.InvoiceDate;
                    model.Order.LastStatusChangeDate = DateTime.Now;
                    model.Order.ValueDate = orderFromDatabase.ValueDate;
                    model.Order.WasAddedToInventory = orderFromDatabase.WasAddedToInventory;
                    model.Order.IsFutureOrder = model.IsFutureOrder;

                    model.Order.Price = totalOrderPrice;

                    ordersRep.Update(model.Order);

                    model.Order = ordersRep.GetEntity(model.Order.Id, "User", "User1");
                }
            }

            if (noErrors)
            {
                int? historyActionId = null;
                historyActionId = (int)HistoryActions.Edited;
                Orders_History orderHistory = new Orders_History();
                using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, model.Order.Id))
                    if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value, model.NotesForApprover);

                if (wasReturnedToCreator)
                {
                    if (model.Order.NextOrderApproverId.HasValue)
                    {
                        SendNotifications.OrderPendingApproval(model.Order, Url);
                    }
                }

                return RedirectToAction("MyOrders");
            }
            else
                return Error(Loc.Dic.error_order_update_items_error);
        }
Exemplo n.º 18
0
        public ActionResult DownloadReceipt(int id = 0)
        {
            Order order;
            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRep.GetEntity(id);

                if (order == null) return Error(Loc.Dic.Error_OrderNotFound);
                if (!Authorized(RoleType.OrdersViewer) && order.UserId != CurrentUser.UserId) return Error(Loc.Dic.Error_NoPermission);
                if (order.StatusId < (int)StatusType.ReceiptScanned) return Error(Loc.Dic.Error_ReceiptNotScanned);

                UploadedFile file = GetUniqueFile(RECEIPT_FOLDER_NAME, id);
                if (file == null) return Error(Loc.Dic.Error_ReceiptFileNotFound);

                return File(file.Content, file.MimeType, String.Format("Order_{0}-Receipt.{1}", order.OrderNumber, file.Extension));
            }
        }
Exemplo n.º 19
0
        public ActionResult Details(int id = 0)
        {
            OrdersRepository.ExeedingOrderData model = new OrdersRepository.ExeedingOrderData();

            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            using (OrderToItemRepository orderItemsRep = new OrderToItemRepository())
            {
                StatusType minStatus = Authorized(RoleType.OrdersApprover) ? StatusType.ApprovedPendingInvoice : StatusType.Pending;
                model = ordersRep.GetOrderWithExeedingData(id, minStatus, "Orders_Statuses", "Supplier", "User", "Orders_OrderToItem.Orders_Items", "Orders_OrderToAllocation", "Orders_OrderToAllocation.Budgets_Allocations", "Budget", "User1");

                if (model == null) return Error(Loc.Dic.error_order_get_error);
                if (!Authorized(RoleType.OrdersViewer) && model.OriginalOrder.UserId != CurrentUser.UserId) return Error(Loc.Dic.error_no_permission);

                return View(model);
            }
        }
Exemplo n.º 20
0
 public GetCurrentUserOrders(OrdersRepository ordersRepository)
 {
     _ordersRepository = ordersRepository;
 }
        public ActionResult Shopping5()
        {
            List <Shopping>      shopping;
            User                 user;
            ShipData             ship;
            JavaScriptSerializer JSONSerializer = new JavaScriptSerializer();

            if (Request.Cookies["shoppingcar"] != null && Request.Cookies["user"] != null && Request.Cookies["ShipData"] != null)
            {
                string json = HttpUtility.UrlDecode(Request.Cookies["shoppingcar"].Value);
                shopping = JSONSerializer.Deserialize <List <Shopping> >(json);
                string json1 = HttpUtility.UrlDecode(Request.Cookies["user"].Value);
                user = JSONSerializer.Deserialize <User>(json1);
                string json2 = HttpUtility.UrlDecode(Request.Cookies["ShipData"].Value);
                ship = JSONSerializer.Deserialize <ShipData>(json2);
                SqlConnection connection = new SqlConnection("data source=.; database=Commerce; integrated security=true");
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    try
                    {
                        var order = new Orders()
                        {
                            MemberID      = user.UserID,
                            EmployeeID    = 1,
                            OrderDate     = DateTime.Now,
                            Discount      = 1,
                            ReceiptedDate = null,
                            ShipName      = ship.ShipName,
                            ShipPhone     = ship.ShipPhone,
                            ShipAddress   = ship.ShipAddress,
                            ShippedDate   = null,
                            Status        = "未出貨"
                        };
                        var orderrepository = new OrdersRepository();
                        orderrepository.Create(order, connection, transaction);
                        var memberrepository      = new MemberRepository();
                        var memberorder           = memberrepository.GetBuyerOrder(user.UserID, connection, transaction);
                        var lastordeer            = memberorder.First();
                        var orderdetailrepository = new OrderDetailsRepository();
                        foreach (var item in shopping)
                        {
                            OrderDetails od = new OrderDetails()
                            {
                                OrderID         = lastordeer.OrderID,
                                ProductFormatID = item.ProductFormatID,
                                Quantity        = item.Quantity,
                                UnitPrice       = item.UnitPrice
                            };
                            orderdetailrepository.Create(od, connection, transaction);
                        }
                        transaction.Commit();
                        return(RedirectToAction("Shopping6", "Shopping"));
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(RedirectToAction("", "Shopping"));
                    }
                }
            }
            else
            {
                return(RedirectToAction("", "Shopping"));
            }
            //做order跟orderdetail
        }
Exemplo n.º 22
0
 public static void UpdateOrder(OrderDTO updatedOrder)
 {
     OrdersRepository.UpdateOrder(updatedOrder);
 }
Exemplo n.º 23
0
 public OrdersController(IRepository <Orders> r)
 {
     repo = (OrdersRepository)r;
 }
Exemplo n.º 24
0
 public static ICollection <OrderDTO> GetOrders()
 {
     return(OrdersRepository.GetOrders());
 }
Exemplo n.º 25
0
 public OrdersController()
 {
     _orderRepo = new OrdersRepository(Context);
 }
Exemplo n.º 26
0
        public Order GetOrder(int OrderId)
        {
            var repository = new OrdersRepository(_context);

            return(repository.GetById(OrderId));
        }
Exemplo n.º 27
0
        public ActionResult ModifyStatus(int id = 0)
        {
            if (!Authorized(RoleType.OrdersApprover)) return Error(Loc.Dic.error_no_permission);

            OrdersRepository.ExeedingOrderData model;
            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            using (OrderToItemRepository orderItemsRep = new OrderToItemRepository())
            {
                StatusType minStatus = Authorized(RoleType.OrdersApprover) ? StatusType.ApprovedPendingInvoice : StatusType.Pending;
                model = ordersRep.GetOrderWithExeedingData(id, minStatus, "Orders_Statuses", "Supplier", "User", "User1", "Orders_OrderToItem.Orders_Items", "Orders_OrderToAllocation", "Orders_OrderToAllocation.Budgets_Allocations", "Budget");

                if (model == null) return Error(Loc.Dic.error_order_get_error);
                if ((model.OriginalOrder.NextOrderApproverId != CurrentUser.UserId) && !Authorized(RoleType.SuperApprover)) return Error(Loc.Dic.error_no_permission);
                if (model.OriginalOrder.StatusId == (int)StatusType.OrderCancelled) return Error(Loc.Dic.error_order_is_canceled);
                if (model.OriginalOrder.StatusId >= (int)StatusType.ApprovedPendingInvoice) return Error(Loc.Dic.error_order_already_approved);

                return View(model);
            }
        }
 public OperationOrders(OrdersRepository repository)
 {
     _repository = repository;
 }
Exemplo n.º 29
0
 public OrdersService(OrdersRepository ordersRepository)
 {
     this.ordersRepository = ordersRepository;
 }
Exemplo n.º 30
0
 public void Initialize()
 {
     Repository           = new OrdersRepository();
     TransformationAspect = new OrderTransformationAspect();
 }
        public ActionResult Edit(Budgets_Allocations Budgets_Allocations)
        {
            return(Error(Loc.Dic.error_no_permission));

            if (Authorized(RoleType.SystemManager))
            {
                if (ModelState.IsValid)
                {
                    Budgets_Allocations allocation;
                    Budgets_Incomes     income;
                    Budgets_Expenses    expense;

                    using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
                        using (BudgetsIncomesRepository incomesRep = new BudgetsIncomesRepository())
                            using (BudgetsExpensesRepository expensesRep = new BudgetsExpensesRepository())
                                using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                                    using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                                    {
                                        allocation = allocationsRep.GetEntity(Budgets_Allocations.Id);

                                        if (allocation != null)
                                        {
                                            if (allocation.CompanyId == CurrentUser.CompanyId)
                                            {
                                                income  = incomesRep.GetEntity(Budgets_Allocations.IncomeId.Value);
                                                expense = expensesRep.GetEntity(Budgets_Allocations.ExpenseId.Value);

                                                if (income != null && expense != null)
                                                {
                                                    if (income.BudgetId == allocation.BudgetId && expense.BudgetId == allocation.BudgetId)
                                                    {
                                                        decimal?totalUsed;
                                                        decimal?allocatedToExpense;
                                                        decimal?allocatedToIncome;

                                                        totalUsed = 0; //totalUsed = ordersRep.GetList()
                                                        //    .Where(order => order.BudgetAllocationId == Budgets_Allocations.Id && order.StatusId >= (int)StatusType.ApprovedPendingInvoice)
                                                        //    .Sum(x => (decimal?)x.Price);

                                                        if ((totalUsed ?? 0) > Budgets_Allocations.CompanyId)//if ((totalUsed ?? 0) > Budgets_Allocations.Amount)
                                                        {
                                                            return(Error(Loc.Dic.error_allocations_amount_is_used));
                                                        }

                                                        allocatedToIncome = allocationsRep.GetList()
                                                                            .Where(x => x.IncomeId == income.Id && x.Id != Budgets_Allocations.Id)
                                                                            .Sum(alloc => (decimal?)alloc.CompanyId);                 //.Sum(alloc => (decimal?)alloc.Amount);

                                                        if ((allocatedToIncome ?? 0) + Budgets_Allocations.CompanyId > income.Amount) //if ((allocatedToIncome ?? 0) + Budgets_Allocations.Amount > income.Amount)
                                                        {
                                                            return(Error(Loc.Dic.error_income_full_allocation));
                                                        }

                                                        allocatedToExpense = allocationsRep.GetList()
                                                                             .Where(x => x.ExpenseId == expense.Id && x.Id != Budgets_Allocations.Id)
                                                                             .Sum(alloc => (decimal?)alloc.CompanyId);                  //.Sum(alloc => (decimal?)alloc.Amount);

                                                        if ((allocatedToExpense ?? 0) + Budgets_Allocations.CompanyId > expense.Amount) //if ((allocatedToExpense ?? 0) + Budgets_Allocations.Amount > expense.Amount)
                                                        {
                                                            return(Error(Loc.Dic.error_expenses_full_allocation));
                                                        }

                                                        allocation.IncomeId  = Budgets_Allocations.IncomeId;
                                                        allocation.ExpenseId = Budgets_Allocations.ExpenseId;
                                                        allocation.CompanyId = Budgets_Allocations.CompanyId;//allocation.Amount = Budgets_Allocations.Amount;

                                                        Budgets_Allocations update = allocationsRep.Update(allocation);

                                                        if (update != null)
                                                        {
                                                            return(RedirectToAction("Index"));
                                                        }
                                                        else
                                                        {
                                                            return(Error(Loc.Dic.error_allocations_get_error));
                                                        }
                                                    }
                                                    else
                                                    {
                                                        return(Error(Loc.Dic.error_invalid_form));
                                                    }
                                                }
                                                else
                                                {
                                                    return(Error(Loc.Dic.error_database_error));
                                                }
                                            }
                                            else
                                            {
                                                return(Error(Loc.Dic.error_no_permission));
                                            }
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_allocations_get_error));
                                        }
                                    }
                }
                else
                {
                    return(Error(ModelState));
                }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 32
0
        public ActionResult SuppliersEntrence(int page = FIRST_PAGE, string sortby = NO_SORT_BY, string order = DEFAULT_DESC_ORDER, int VAT_Number = 0)
        {
            CultureInfo ci = new CultureInfo("He");

            System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
            System.Threading.Thread.CurrentThread.CurrentCulture   =
                CultureInfo.CreateSpecificCulture(ci.Name);

            using (SuppliersRepository supRep = new SuppliersRepository(CurrentUser.CompanyId))
                using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
                {
                    Supplier supplier = supRep.GetList().SingleOrDefault(x => x.VAT_Number == VAT_Number);

                    IEnumerable <Order> orders;

                    orders = orderRep.GetList("Orders_Statuses", "Supplier", "User").Where(x => x.SupplierId == supplier.Id);

                    if (orders != null)
                    {
                        int numberOfItems = orders.Count();
                        int numberOfPages = numberOfItems / ITEMS_PER_PAGE;
                        if (numberOfItems % ITEMS_PER_PAGE != 0)
                        {
                            numberOfPages++;
                        }

                        if (page <= 0)
                        {
                            page = FIRST_PAGE;
                        }
                        if (page > numberOfPages)
                        {
                            page = numberOfPages;
                        }

                        if (sortby != NO_SORT_BY)
                        {
                            Func <Func <Order, dynamic>, IEnumerable <Order> > orderFunction;

                            if (order == DEFAULT_DESC_ORDER)
                            {
                                orderFunction = x => orders.OrderByDescending(x);
                            }
                            else
                            {
                                orderFunction = x => orders.OrderBy(x);
                            }

                            switch (sortby)
                            {
                            case "username":
                            default:
                                orders = orderFunction(x => x.User.FirstName + " " + x.User.LastName);
                                break;

                            case "number":
                                orders = orderFunction(x => x.OrderNumber);
                                break;

                            case "creation":
                                orders = orderFunction(x => x.CreationDate);
                                break;

                            case "supplier":
                                orders = orderFunction(x => x.Supplier.Name);
                                break;

                            case "status":
                                orders = orderFunction(x => x.StatusId);
                                break;

                            case "price":
                                orders = orderFunction(x => x.Price);
                                break;
                            }
                        }

                        orders = orders
                                 .Skip((page - 1) * ITEMS_PER_PAGE)
                                 .Take(ITEMS_PER_PAGE)
                                 .ToList();

                        ViewBag.Sortby        = sortby;
                        ViewBag.Order         = order;
                        ViewBag.CurrPage      = page;
                        ViewBag.NumberOfPages = numberOfPages;

                        return(View(orders.ToList()));
                    }
                    else
                    {
                        return(Error(Loc.Dic.error_order_get_error));
                    }
                }
        }
Exemplo n.º 33
0
 public OrdersApiController()
 {
     ordersRepo = new OrdersRepository();
 }
Exemplo n.º 34
0
 public OrdersPoxController(OrdersRepository repository)
 {
     ordersRepository = repository;
 }
Exemplo n.º 35
0
        public ActionResult DownloadInvoice(int id = 0)
        {
            Order order;

            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRep.GetEntity(id);

                if (order == null) return Error(Loc.Dic.Error_OrderNotFound);
                if (!Authorized(RoleType.OrdersViewer) && order.UserId != CurrentUser.UserId) return Error(Loc.Dic.Error_NoPermission);
                if (order.StatusId < (int)StatusType.InvoiceScannedPendingOrderCreator) return Error(Loc.Dic.Error_InvoiceNotScanned);

                UploadedFile file = GetUniqueFile(INVOICE_FOLDER_NAME, id);
                if (file == null) return Error(Loc.Dic.Error_InvoiceFileNotFound);

                return File(file.Content, file.MimeType, String.Format("Order_{0}-Invoice_{1}.{2}", order.OrderNumber, order.InvoiceNumber, file.Extension));
            }
        }
Exemplo n.º 36
0
 public LoginController()
 {
     ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
     OrdersRepository = new OrdersRepository(ConnectionString);
 }
Exemplo n.º 37
0
        public ActionResult DownloadOrderAsPdf(int id = 0)
        {
            string cookieName = OpenIdMembershipService.LOGIN_COOKIE_NAME;
            HttpCookie cookie = Request.Cookies[cookieName];
            Dictionary<string, string> cookies = new Dictionary<string, string>();
            cookies.Add(cookieName, cookie.Value);
            int? historyActionId = null;

            Order order;
            using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, id))

            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRep.GetEntity(id);

                historyActionId = (int)HistoryActions.OrderPrinted;
                Orders_History orderHistory = new Orders_History();
                if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value);
            }

            return new ActionAsPdf("PrintOrderToScreen", new { password = PRINT_PASSWORD, id = id, companyId = CurrentUser.CompanyId, userId = CurrentUser.UserId, userRoles = CurrentUser.Roles, languageCode = CurrentUser.LanguageCode, coinSign = CurrentUser.CompanyCoinSign }) { FileName = String.Format("Order_{0}.pdf", order.OrderNumber) };
        }
Exemplo n.º 38
0
        public ActionResult AllOrdersForPrint()
        {
            OrdersRepository repo = new OrdersRepository();

            return(View(repo.GetAllOrders()));
        }
Exemplo n.º 39
0
        public ActionResult Edit(int id = 0)
        {
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);

            CreateOrderModel model = new CreateOrderModel();
            using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
            using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
            using (BudgetsRepository budgetsRep = new BudgetsRepository(CurrentUser.CompanyId))
            {
                model.Order = orderRep.GetEntity(id, "Supplier", "Orders_OrderToItem", "Orders_OrderToItem.Orders_Items", "Orders_OrderToAllocation.Budgets_Allocations");
                if (model.Order == null) return Error(Loc.Dic.error_order_not_found);
                if (model.Order.UserId != CurrentUser.UserId) return Error(Loc.Dic.error_no_permission);

                Budget activeBudget = budgetsRep.GetList().SingleOrDefault(x => x.CompanyId == CurrentUser.CompanyId && x.IsActive);
                if (activeBudget == null) return Error(Loc.Dic.error_no_active_budget);

                model.IsFutureOrder = model.Order.IsFutureOrder;

                List<Budgets_Allocations> userAllocations = allocationsRep.GetUserAllocations(CurrentUser.UserId, activeBudget.Id, id);
                if (!userAllocations.Any()) return Error(Loc.Dic.error_user_have_no_allocations);

                model.Allocations = new List<OrderAllocation>();
                List<Orders_OrderToAllocation> validOrderAllocations = model.Order.Orders_OrderToAllocation.ToList();

                var distinctAllocationIds = validOrderAllocations.Select(x => x.AllocationId).Distinct().ToList();
                foreach (var allocationId in distinctAllocationIds)
                {
                    var combineSplitted = validOrderAllocations.Where(x => x.MonthId <= model.Order.CreationDate.Month && x.AllocationId == allocationId);
                    model.Allocations.Add(
                        new OrderAllocation()
                            {
                                AllocationId = allocationId,
                                Name = validOrderAllocations.First(x => x.AllocationId == allocationId).Budgets_Allocations.DisplayName,
                                MonthId = model.Order.CreationDate.Month,
                                IsActive = true,
                                Amount = combineSplitted.Sum(x => x.Amount)
                            }
                    );

                    validOrderAllocations.RemoveAll(x => x.MonthId <= model.Order.CreationDate.Month && x.AllocationId == allocationId);
                }

                foreach (var allocation in validOrderAllocations)
                {
                    model.Allocations.Add(
                        new OrderAllocation()
                        {
                            AllocationId = allocation.AllocationId,
                            Name = allocation.Budgets_Allocations.Name,
                            MonthId = allocation.MonthId,
                            IsActive = true,
                            Amount = allocation.Amount
                        }
                    );
                }

                ViewBag.Allocations = userAllocations;

                int allAllocationsCount = model.Allocations.Count;
                model.Allocations = model.Allocations.Where(x => userAllocations.Any(a => a.Id == x.AllocationId)).ToList();
                int validAllocationsCount = model.Allocations.Count;

                ViewBag.ReAllocationRequired = allAllocationsCount > validAllocationsCount;
                ViewBag.BudgetYear = activeBudget.Year;
                ViewBag.ExistingItems = ItemsToString(model.Order.Orders_OrderToItem);
                return View(model);
            }
        }
Exemplo n.º 40
0
        public ActionResult OrderDetailsForPrint(int orderId)
        {
            OrdersRepository repo = new OrdersRepository();

            return(View(repo.GetOrderWithDetailsByOrderId(orderId)));
        }
Exemplo n.º 41
0
        public ActionResult AddToInventory(AddToInventoryModel model)
        {
            if (!Authorized(RoleType.InventoryManager)) return Error(Loc.Dic.error_no_permission);

            Order order;
            List<Inventory> createdItems = new List<Inventory>();
            List<Location> locations;
            bool noCreationErrors = true;

            using (InventoryRepository inventoryRep = new InventoryRepository(CurrentUser.CompanyId))
            using (LocationsRepository locationsRep = new LocationsRepository(CurrentUser.CompanyId))
            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRep.GetEntity(model.OrderId, "Supplier", "Orders_OrderToItem", "Orders_OrderToItem.Orders_Items");

                if (order == null) return Error(Loc.Dic.error_order_get_error);
                if (order.WasAddedToInventory) return Error(Loc.Dic.error_order_was_added_to_inventory);
                if (order.StatusId < (int)StatusType.InvoiceApprovedByOrderCreatorPendingFileExport) return Error(Loc.Dic.error_invoice_not_scanned_and_approved);

                locations = locationsRep.GetList().ToList();
                if (locations == null || locations.Count == 0) return Error(Loc.Dic.error_no_locations_found);

                foreach (SplittedInventoryItem splitedItem in model.InventoryItems)
                {
                    if (!noCreationErrors) break;
                    if (!splitedItem.AddToInventory) continue;

                    int? itemId = splitedItem.ItemsToAdd[0].ItemId;
                    Orders_OrderToItem originalItem = order.Orders_OrderToItem.FirstOrDefault(x => x.Id == itemId);
                    bool isValidList = originalItem != null && splitedItem.ItemsToAdd.All(x => x.ItemId == itemId);

                    if (!isValidList) { noCreationErrors = false; break; }

                    if (splitedItem.ItemsToAdd.Count == 1)
                    {
                        Inventory listItem = splitedItem.ItemsToAdd[0];
                        if (!locations.Any(x => x.Id == listItem.LocationId)) return Error(Loc.Dic.error_invalid_form);

                        Inventory newItem = new Inventory()
                        {
                            AssignedTo = listItem.AssignedTo,
                            LocationId = listItem.LocationId,
                            Notes = listItem.Notes,
                            SerialNumber = listItem.SerialNumber,
                            Status = listItem.Status,
                            WarrentyPeriodStart = listItem.WarrentyPeriodStart,
                            WarrentyPeriodEnd = listItem.WarrentyPeriodEnd,
                            ItemId = originalItem.ItemId,
                            OrderId = order.Id,
                            CompanyId = CurrentUser.CompanyId,
                            IsOutOfInventory = false,
                            OriginalQuantity = originalItem.Quantity,
                            RemainingQuantity = originalItem.Quantity
                        };

                        if (!inventoryRep.Create(newItem)) { noCreationErrors = false; break; }
                        createdItems.Add(newItem);
                    }
                    else if (originalItem.Quantity == splitedItem.ItemsToAdd.Count)
                    {
                        foreach (var item in splitedItem.ItemsToAdd)
                        {
                            if (!locations.Any(x => x.Id == item.LocationId)) { noCreationErrors = false; break; }

                            item.ItemId = originalItem.ItemId;
                            item.OrderId = order.Id;
                            item.CompanyId = CurrentUser.CompanyId;
                            item.IsOutOfInventory = false;

                            if (!inventoryRep.Create(item)) { noCreationErrors = false; break; }
                            createdItems.Add(item);
                        }
                    }
                    else { noCreationErrors = false; break; }
                }

                if (!noCreationErrors)
                {
                    foreach (var item in createdItems)
                    {
                        inventoryRep.Delete(item.Id);
                    }

                    return Error(Loc.Dic.error_inventory_create_error);
                }

                order.WasAddedToInventory = true;
                order.LastStatusChangeDate = DateTime.Now;
                if (ordersRep.Update(order) == null) return Error(Loc.Dic.error_database_error);

                bool hasInventoryItems = model.InventoryItems.Any(x => x.AddToInventory);
                string notes = hasInventoryItems ? Loc.Dic.AddToInventory_with_inventory_items : Loc.Dic.AddToInventory_no_inventory_items;

                int? historyActionId = null;
                historyActionId = (int)HistoryActions.AddedToInventory;
                Orders_History orderHistory = new Orders_History();
                using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, order.Id))
                    if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value, notes);

                return RedirectToAction("PendingInventory");
            }
        }
Exemplo n.º 42
0
        public ActionResult ProductsOrderedCount()
        {
            var repo = new OrdersRepository();

            return(View(repo.ProductsSold()));
        }
Exemplo n.º 43
0
        public ActionResult InvoiceApproval(int id = 0)
        {
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);

            Order order;
            using (OrdersRepository ordersRepository = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRepository.GetEntity(id);
            }

            if (order == null) return Error(Loc.Dic.error_order_not_found);
            if (order.UserId != CurrentUser.UserId) return Error(Loc.Dic.error_no_permission);

            ViewBag.orderId = id;
            return View();
        }
Exemplo n.º 44
0
        public ActionResult DeleteConfirmed(int id, int budgetId)
        {
            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Baskets permission;

                using (OrdersRepository orderssRep = new OrdersRepository(CurrentUser.CompanyId))
                    using (BudgetsPermissionsRepository permissionsRep = new BudgetsPermissionsRepository())
                        using (BasketsToAllocationsRepository permissionsAllocationsRep = new BasketsToAllocationsRepository())
                            using (UsersToBasketsRepository usersPermissionsRep = new UsersToBasketsRepository())
                            {
                                permission = permissionsRep.GetEntity(id);

                                if (permission != null)
                                {
                                    if (permission.CompanyId == CurrentUser.CompanyId)
                                    {
                                        bool       noErrors = true;
                                        List <int> permissionAllocations = permission.Budgets_BasketsToAllocation.Select(x => x.Id).ToList();
                                        List <int> usersPermissions      = permission.Budgets_UsersToBaskets.Select(x => x.Id).ToList();

                                        foreach (var itemId in permissionAllocations)
                                        {
                                            if (!permissionsAllocationsRep.Delete(itemId))
                                            {
                                                noErrors = false;
                                            }
                                        }

                                        foreach (var itemId in usersPermissions)
                                        {
                                            if (!usersPermissionsRep.Delete(itemId))
                                            {
                                                noErrors = false;
                                            }
                                        }

                                        if (!permissionsRep.Delete(permission.Id))
                                        {
                                            noErrors = false;
                                        }

                                        if (noErrors)
                                        {
                                            return(RedirectToAction("Index", new { id = budgetId }));
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_permissions_delete_error));
                                        }
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_no_permission));
                                    }
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_projects_get_error));
                                }
                            }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 45
0
        public ActionResult ListOrderAllocations(IEnumerable<Orders_OrderToAllocation> orderAllocations, int budgetYear, bool isFutureOrder, string baseUrl, OrdersRepository.ExeedingOrderData exeedingData = null)
        {
            ViewBag.BaseUrl = baseUrl;
            ViewBag.IsOrdered = false;
            ViewBag.IsPaged = false;
            ViewBag.Sortby = null;
            ViewBag.Order = null;
            ViewBag.CurrPage = 1;
            ViewBag.NumberOfPages = 1;

            ViewBag.IsCheckBoxed = false;
            ViewBag.ShowUserName = true;
            ViewBag.IsFutureOrder = isFutureOrder;
            ViewBag.BudgetYear = budgetYear;

            ViewBag.ExeedingData = exeedingData;

            return PartialView(orderAllocations);
        }
Exemplo n.º 46
0
 public HomeController(NorthwindDbContext context, ICompositeViewEngine compositeViewEngine) : base(compositeViewEngine)
 {
     _orderRepository        = new OrdersRepository(context);
     _orderDetailsRepository = new OrderDetailsRepository(context);
     _customersRepository    = new CustomersRepository(context);
 }
Exemplo n.º 47
0
 public ActionResult Grid()
 {
     var repository = new OrdersRepository();
     var grid = new OrdersGrid(repository.GetAll());
     return PartialView("_OrdersGrid", grid);
 }
Exemplo n.º 48
0
        public ActionResult ProductSizeStock(int pId, int sId)
        {
            var repo = new OrdersRepository();

            return(Json(repo.ProductSizeStock(pId, sId), JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 49
0
 public UserCartService() : base()
 {
     _ordersRepository = new OrdersRepository();
 }
Exemplo n.º 50
0
 public OrdersService(OrdersRepository repo, ShoesRepository shoeRepo)
 {
     _shoeRepo = shoeRepo;
     _repo     = repo;
 }
Exemplo n.º 51
0
        private bool OrderExists(int key)
        {
            var repository = new OrdersRepository(_context);

            return(repository.GetAll().Any(x => x.OrderID == key));
        }
Exemplo n.º 52
0
        public ActionResult Delete(int id = 0)
        {
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);

            OrdersRepository.ExeedingOrderData model = new OrdersRepository.ExeedingOrderData();
            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                StatusType minStatus = Authorized(RoleType.OrdersApprover) ? StatusType.ApprovedPendingInvoice : StatusType.Pending;
                model = ordersRep.GetOrderWithExeedingData(id, minStatus, "Orders_Statuses", "Supplier", "User", "Orders_OrderToItem.Orders_Items", "Orders_OrderToAllocation", "Orders_OrderToAllocation.Budgets_Allocations", "Budget", "User1");
            }

            if (model == null) return Error(Loc.Dic.error_order_not_found);
            if (model.OriginalOrder.UserId != CurrentUser.UserId) return Error(Loc.Dic.error_no_permission);
            if (model.OriginalOrder.StatusId != (int)StatusType.Pending && model.OriginalOrder.StatusId != (int)StatusType.PendingOrderCreator)
                return Error(Loc.Dic.error_order_delete_after_approval);

            ViewBag.OrderId = model.OriginalOrder.Id;
            return View(model);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            return(Error(Loc.Dic.error_no_permission));

            if (Authorized(RoleType.SystemManager))
            {
                Budgets_Allocations allocation;
                using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
                    using (AllocationRepository allocationsRep = new AllocationRepository(CurrentUser.CompanyId))
                        using (BasketsToAllocationsRepository allocationsPermissionsRep = new BasketsToAllocationsRepository())
                        {
                            allocation = allocationsRep.GetEntity(id, "Budgets_Incomes", "Budgets_Expenses");

                            if (allocation != null)
                            {
                                if (allocation.CompanyId == CurrentUser.CompanyId)
                                {
                                    if (false) //if (allocation.Orders.All(x => x.StatusId < (int)StatusType.ApprovedPendingInvoice))
                                    {
                                        bool         noErrors         = true;
                                        List <Order> allocationOrders = new List <Order>();//List<Order> allocationOrders = allocation.Orders.ToList();

                                        foreach (var item in allocationOrders)
                                        {
                                            item.StatusId             = (int)StatusType.Declined;
                                            item.LastStatusChangeDate = DateTime.Now;

                                            //item.OrderApproverNotes = YOUR_ALLOCATION_WAS_REVOKED;
                                            item.NextOrderApproverId = null;

                                            if (ordersRep.Update(item) == null)
                                            {
                                                noErrors = false;
                                            }
                                        }

                                        List <int> allocationPermission = allocation.Budgets_BasketsToAllocation.Select(x => x.Id).ToList();
                                        foreach (var itemId in allocationPermission)
                                        {
                                            if (!allocationsPermissionsRep.Delete(itemId))
                                            {
                                                noErrors = false;
                                            }
                                        }

                                        if (!allocationsRep.Delete(allocation.Id))
                                        {
                                            noErrors = false;
                                        }

                                        if (noErrors)
                                        {
                                            return(RedirectToAction("Index"));
                                        }
                                        else
                                        {
                                            return(Error(Loc.Dic.error_allocations_delete_error));
                                        }
                                    }
                                    else
                                    {
                                        return(Error(Loc.Dic.error_allocations_has_approved_orders));
                                    }
                                }
                                else
                                {
                                    return(Error(Loc.Dic.error_no_permission));
                                }
                            }
                            else
                            {
                                return(Error(Loc.Dic.error_income_get_error));
                            }
                        }
            }
            else
            {
                return(Error(Loc.Dic.error_no_permission));
            }
        }
Exemplo n.º 54
0
        public ActionResult DeleteConfirmed(int id = 0)
        {
            if (!Authorized(RoleType.OrdersWriter)) return Error(Loc.Dic.error_no_permission);

            Order order;
            using (OrderToItemRepository orderToItemRep = new OrderToItemRepository())
            using (OrderToAllocationRepository orderToAllocationRep = new OrderToAllocationRepository())
            using (OrdersRepository orderRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = orderRep.GetEntity(id);

                if (order == null) return Error(Loc.Dic.error_order_not_found);
                if (order.UserId != CurrentUser.UserId) return Error(Loc.Dic.error_no_permission);
                if (order.StatusId != (int)StatusType.Pending && order.StatusId != (int)StatusType.PendingOrderCreator)
                    return Error(Loc.Dic.error_order_delete_after_approval);

                if (!orderRep.Delete(order.Id)) return Error(Loc.Dic.error_orders_delete_error);
            }

            return RedirectToAction("MyOrders");
        }
Exemplo n.º 55
0
 public OrdersController()
 {
     ordersRepository = new OrdersRepository(Config.ConnectionString);
 }
Exemplo n.º 56
0
 public OrdersService(OrdersRepository repo, ItemsRepository itemRepo)
 {
     _repo     = repo;
     _itemRepo = itemRepo;
 }
Exemplo n.º 57
0
        public async Task <IViewComponentResult> InvokeAsync(string ordersGridState = "")
        {
            IQueryCollection query = Request.Query;

            if (!string.IsNullOrWhiteSpace(ordersGridState))
            {
                try
                {
                    query = new QueryCollection(StringExtensions.GetQuery(ordersGridState));
                }
                catch (Exception)
                {
                    // do nothing, gridState was not a valid state
                }
            }

            Action <IGridColumnCollection <Order> > columns = c =>
            {
                /* Adding not mapped column, that renders body, using inline Razor html helper */
                c.Add()
                .Encoded(false)
                .Sanitized(false)
                .SetWidth(30)
                .Css("hidden-xs")     //hide on phones
                .RenderValueAs(o => $"<b><a class='modal_link' href='javascript:void(0);' onclick='editOrder({o.OrderID})'>Edit</a></b>");

                /* Adding "OrderID" column: */

                c.Add(o => o.OrderID)
                .Titled("Number")
                .SetWidth(100);

                /* Adding "OrderDate" column: */
                c.Add(o => o.OrderDate, "OrderCustomDate")
                .Titled("Date")
                .SortInitialDirection(GridSortDirection.Descending)
                .ThenSortByDescending(o => o.OrderID)
                .SetCellCssClassesContraint(o => o.OrderDate.HasValue && o.OrderDate.Value >= DateTime.Parse("1997-01-01") ? "red" : "")
                .Format("{0:yyyy-MM-dd}")
                .SetWidth(110)
                .Max(true).Min(true);

                /* Adding "CompanyName" column: */
                c.Add(o => o.Customer.CompanyName)
                .Titled("Company")
                .SetWidth(250)
                .SetInitialFilter(GridFilterType.StartsWith, "a")
                .SetFilterWidgetType("CustomCompanyNameFilterWidget")
                .Max(true).Min(true);

                /* Adding "ContactName" column: */
                c.Add(o => o.Customer.ContactName).Titled("ContactName").SetWidth(250)
                .Max(true).Min(true);

                /* Adding "Freight" column: */
                c.Add(o => o.Freight)
                .Titled("Freight")
                .SetWidth(100)
                .Format("{0:F}")
                .Sum(true).Average(true).Max(true).Min(true);

                /* Adding "Vip customer" column: */
                c.Add(o => o.Customer.IsVip)
                .Titled("Is Vip")
                .SetWidth(70)
                .Css("hidden-xs")     //hide on phones
                .RenderValueAs(o => o.Customer.IsVip ? "Yes" : "No");
            };

            var repository     = new OrdersRepository(_context);
            var requestCulture = HttpContext.Features.Get <IRequestCultureFeature>();
            var locale         = requestCulture.RequestCulture.UICulture.TwoLetterISOLanguageName;

            var server = new GridServer <Order>(repository.GetAll(), query, false, "ordersGrid",
                                                columns, 10, locale, GridPager.DefaultAjaxPagerViewName)
                         .SetRowCssClasses(item => item.Customer.IsVip ? "success" : string.Empty)
                         .Sortable()
                         .Filterable()
                         .WithMultipleFilters()
                         .Searchable(true, false)
                         .Groupable(true)
                         .Selectable(true)
                         .WithGridItemsCount();
            var factory = Task <IViewComponentResult> .Factory;

            return(await factory.StartNew(() => View(server.Grid)));
        }
Exemplo n.º 58
0
        public ActionResult Index()
        {
            ViewBag.ActiveMenuTitle = "Demo";

            Action <IGridColumnCollection <Order> > columns = c =>
            {
                /* Adding not mapped column, that renders body, using inline Razor html helper */
                c.Add()
                .Encoded(false)
                .Sanitized(false)
                .SetWidth(30)
                .Css("hidden-xs")     //hide on phones
                .RenderValueAs(o => $"<b><a class='modal_link' href='/Home/Edit/{o.OrderID}'>Edit</a></b>");

                /* Adding "OrderID" column: */

                c.Add(o => o.OrderID)
                .Titled("Number")
                .SetWidth(100);

                /* Adding "OrderDate" column: */
                c.Add(o => o.OrderDate, "OrderCustomDate")
                .Titled("Date")
                .SortInitialDirection(GridSortDirection.Descending)
                .SetCellCssClassesContraint(o => o.OrderDate.HasValue && o.OrderDate.Value >= DateTime.Parse("1997-01-01") ? "red" : "")
                .Format("{0:yyyy-MM-dd}")
                .SetWidth(110)
                .Max(true).Min(true);

                /* Adding "CompanyName" column: */
                c.Add(o => o.Customer.CompanyName)
                .Titled("Company")
                .SetWidth(250)
                .ThenSortByDescending(o => o.OrderID)
                .SetInitialFilter(GridFilterType.StartsWith, "a")
                .SetFilterWidgetType("CustomCompanyNameFilterWidget")
                .Max(true).Min(true);

                /* Adding "ContactName" column: */
                c.Add(o => o.Customer.ContactName).Titled("ContactName").SetWidth(250)
                .Max(true).Min(true);

                /* Adding "Freight" column: */
                c.Add(o => o.Freight)
                .Titled("Freight")
                .SetWidth(100)
                .Format("{0:F}")
                .Sum(true).Average(true).Max(true).Min(true);

                /* Adding "Vip customer" column: */
                c.Add(o => o.Customer.IsVip)
                .Titled("Is Vip")
                .SetWidth(70)
                .Css("hidden-xs")     //hide on phones
                .RenderValueAs(o => o.Customer.IsVip ? "Yes" : "No");
            };
            var requestCulture = HttpContext.Features.Get <IRequestCultureFeature>();
            var locale         = requestCulture.RequestCulture.UICulture.TwoLetterISOLanguageName;

            var repository = new OrdersRepository(_context);
            var server     = new GridServer <Order>(repository.GetAll(), Request.Query, false, "ordersGrid",
                                                    columns, 10, locale)
                             .SetRowCssClasses(item => item.Customer.IsVip ? "success" : string.Empty)
                             .Sortable()
                             .Filterable()
                             .WithMultipleFilters()
                             .Searchable(true, false)
                             .WithGridItemsCount();

            return(View(server.Grid));
        }
Exemplo n.º 59
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (Authorized(RoleType.SystemManager))
            {
                Projects_ParentProject project;

                using (OrdersRepository orderssRep = new OrdersRepository(CurrentUser.CompanyId))
                using (ParentProjectsRepository projectsRep = new ParentProjectsRepository())
                {
                    project = projectsRep.GetEntity(id);

                    if (project != null)
                    {
                        if (project.CompanyId == CurrentUser.CompanyId)
                        {
                            project.IsActive = false;
                            Projects_ParentProject update = projectsRep.Update(project);

                            if (update != null)
                                return RedirectToAction("Index");
                            else
                                return Error(Loc.Dic.error_projects_get_error);
                        }
                        else
                        {
                            return Error(Loc.Dic.error_no_permission);
                        }
                    }
                    else
                    {
                        return Error(Loc.Dic.error_projects_get_error);
                    }
                }
            }
            else
            {
                return Error(Loc.Dic.error_no_permission);
            }
        }
Exemplo n.º 60
0
 public OrdersController(OrdersRepository ordersRepository, OrderService orderService)
 {
     this.ordersRepository = ordersRepository;
     this.orderService     = orderService;
 }