public ActionResult UploadReceiptFile(UploadReceiptModel model, int id = 0)
        {
            if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.Error_NoPermission);

            if (!ModelState.IsValid)
            {
                ViewBag.OrderID = id;
                return View(model);
            }

            Order order;
            bool isModelValid = true;
            int? historyActionId = null;

            using (OrdersHistoryRepository ordersHistoryRep = new OrdersHistoryRepository(CurrentUser.CompanyId, CurrentUser.UserId, id))
            using (OrdersRepository ordersRep = new OrdersRepository(CurrentUser.CompanyId))
            {
                order = ordersRep.GetEntity(id);

                if (order == null) return Error(Loc.Dic.Error_OrderNotFound);
                if (order.StatusId < (int)StatusType.InvoiceExportedToFile) return Error(Loc.Dic.error_wrongStatus);

                if (!model.File.FileName.Contains('.'))
                {
                    isModelValid = false;
                    ModelState.AddModelError("File", Loc.Dic.validation_FileNameIsInvalid);
                }

                if (!isModelValid)
                {
                    ViewBag.OrderID = id;
                    return View(model);
                }

                if (!model.isUpdate)
                {
                    order.StatusId = (int)StatusType.ReceiptScanned;
                    order.LastStatusChangeDate = DateTime.Now;
                    if (ordersRep.Update(order) == null) return Error(Loc.Dic.Error_DatabaseError);
                }

                SaveUniqueFile(model.File, RECEIPT_FOLDER_NAME, id);
                historyActionId = (int)HistoryActions.ReceiptScanned;
                Orders_History orderHistory = new Orders_History();
                if (historyActionId.HasValue) ordersHistoryRep.Create(orderHistory, historyActionId.Value);

                //EmailMethods emailMethods = new EmailMethods("*****@*****.**", Loc.Dic.OrdersSystem, "noreply50100200");
                //emailMethods.sendGoogleEmail(order.User.Email, order.User.FirstName, Loc.Dic.OrderStatusUpdateEvent, Loc.Dic.OrderStatusOf + order.OrderNumber + Loc.Dic.OrderStatusChangedTo + Translation.Status((StatusType)order.StatusId) + Url.Action("MyOrders", "Orders", null, "http"));

                SendNotifications.OrderStatusChanged(order, CurrentUser, Url);

                return RedirectToAction("Index");
            }
        }
        public ActionResult UploadReceiptFile(int id = 0)
        {
            if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.Error_NoPermission);

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

                if (order == null) return Error(Loc.Dic.Error_OrderNotFound);
                if (order.StatusId < (int)StatusType.InvoiceExportedToFile) return Error(Loc.Dic.error_wrongStatus);

                ViewBag.OrderId = id;
                if (order.StatusId >= (int)StatusType.ReceiptScanned)
                {
                    UploadReceiptModel model = new UploadReceiptModel();
                    model.isUpdate = true;

                    return View(model);
                }
                else
                {
                    return View();
                }
            }
        }