Example #1
0
        public async Task <OperationStatusInfo> getNotesByAccountId(int accountId)
        {
            return(await Task.Run(() =>
            {
                var operationStatusInfo = new OperationStatusInfo(OperationStatus.Done);
                var getNotesRequestEvent = new GetNotesRequestEvent(accountId);

                try
                {
                    var response =
                        this.useCaseFactory.Create <IUseCase <GetNotesRequestEvent, GetNotesResponseEvent> >().Execute(getNotesRequestEvent);

                    operationStatusInfo.AttachedObject = response.NotesDTO;

                    return operationStatusInfo;
                }
                catch (Exception ex)
                {
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #2
0
        public async Task <OperationStatusInfo> UpdateUser(object userToUpdate)
        {
            return(await Task.Run(() =>
            {
                var operationStatusInfo = new OperationStatusInfo(OperationStatus.Done);

                var attachedObjectText = userToUpdate.ToString();
                var newUser = JsonConvert.DeserializeObject <UserDTO>(attachedObjectText);

                var editUserRequestEvent = new EditUserRequestEvent(newUser);

                try
                {
                    var response =
                        this.useCaseFactory.Create <IUseCase <EditUserRequestEvent, EditUserResponseEvent> >().Execute(editUserRequestEvent);

                    operationStatusInfo.AttachedObject = response.UserDTO;

                    return operationStatusInfo;
                }
                catch (Exception ex)
                {
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #3
0
        public async Task <OperationStatusInfo> DeleteUser(int userId)
        {
            return(await Task.Run(() =>
            {
                var operationStatusInfo = new OperationStatusInfo(OperationStatus.Done);
                var deleteUserRequestEvent = new DeleteUserRequestEvent(userId);

                try
                {
                    var response =
                        this.useCaseFactory.Create <IUseCase <DeleteUserRequestEvent, DeleteUserResponseEvent> >().Execute(deleteUserRequestEvent);

                    operationStatusInfo.AttachedObject = response;

                    return operationStatusInfo;
                }
                catch (Exception ex)
                {
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #4
0
        public async Task <OperationStatusInfo> RegistrationUser(UserDTO user)
        {
            return(await Task.Run(() =>
            {
                var operationStatusInfo = new OperationStatusInfo(OperationStatus.Done);
                var createUserRequestEvent = new CreateUserRequestEvent(user);

                try
                {
                    var response =
                        this.useCaseFactory.Create <IUseCase <CreateUserRequestEvent, CreateUserResponseEvent> >().Execute(createUserRequestEvent);

                    operationStatusInfo.AttachedObject = response.UserDTO;

                    return operationStatusInfo;
                }
                catch (Exception ex)
                {
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #5
0
        public async Task <OperationStatusInfo> Login(string login, string password)
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);
                LoginRequestEvent request = new LoginRequestEvent(login, password);

                try
                {
                    LoginResponseEvent response =
                        _hubEnvironment.UseCaseFactory.Create <IUseCase <LoginRequestEvent, LoginResponseEvent> >().Execute(request);

                    operationStatusInfo.AttachedObject = response.Account;

                    return operationStatusInfo;
                }
                catch (Exception ex)
                {
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #6
0
        public async Task <OperationStatusInfo> GetCustomerById(int id)
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);
                GetCustomerByIdRequestEvent request = new GetCustomerByIdRequestEvent(id);

                try
                {
                    GetCustomerByIdResponseEvent response =
                        _hubEnvironment.UseCaseFactory.Create <IUseCase <GetCustomerByIdRequestEvent, GetCustomerByIdResponseEvent> >().Execute(request);

                    operationStatusInfo.AttachedObject = response.Customer;

                    return operationStatusInfo;
                }
                catch (Exception ex)
                {
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #7
0
        public async Task <OperationStatusInfo> CreateEmployee(Employee employee)
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);
                CreateEmployeeRequestEvent request = new CreateEmployeeRequestEvent(employee);

                try
                {
                    CreateEmployeeResponseEvent response =
                        _hubEnvironment.UseCaseFactory.Create <IUseCase <CreateEmployeeRequestEvent, CreateEmployeeResponseEvent> >().Execute(request);

                    operationStatusInfo.AttachedObject = response.Status;

                    return operationStatusInfo;
                }
                catch (Exception ex)
                {
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #8
0
        public async Task <OperationStatusInfo> AddSales(object addedSale)
        {
            return(await Task.Run(() =>
            {
                Dictionary <Type, object> collection = new Dictionary <Type, object>();
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);

                string attachedSaleObjectText = addedSale.ToString();
                Sale newSale = JsonConvert.DeserializeObject <Sale>(attachedSaleObjectText);
                AddSaleRequest addSaleRequest = new AddSaleRequest(newSale.Product, newSale.Count.ToString(),
                                                                   newSale.Datetime.ToString(), newSale.Price.ToString(), newSale.Seller);

                try
                {
                    AddSaleResponse addSaleResponse = hubEnvironment.UseCaseFactory
                                                      .Create <IUseCase <AddSaleRequest, AddSaleResponse> >()
                                                      .Execute(addSaleRequest);
                    collection.Add(typeof(List <Sale>), addSaleResponse.Sales);
                    collection.Add(typeof(List <Product>), addSaleResponse.Products);
                    operationStatusInfo.AttachedObject = collection;
                    operationStatusInfo.AttachedInfo = "Sale is added!";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
        public async Task <UserDTO> Login(string login, string password)
        {
            try
            {
                this.cts = new CancellationTokenSource(this.serviceEnvironment.OperationTimeout);

                var paramsToSend = new object[] { login, password };

                OperationStatusInfo operationStatusInfo =
                    await this.serviceEnvironment.Connection.InvokeCoreAsync <OperationStatusInfo>("Login", paramsToSend, this.cts.Token);

                if (operationStatusInfo.OperationStatus == OperationStatus.Done)
                {
                    string  attachedObjectText = operationStatusInfo.AttachedObject.ToString();
                    UserDTO user = JsonConvert.DeserializeObject <UserDTO>(attachedObjectText);
                    return(user);
                }
                else
                {
                    throw new Exception(operationStatusInfo.AttachedInfo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{ex.Message}", ex);
            }
        }
Example #10
0
        //Ассинхронный вход пользователя
        public async Task <UserDTO> EnterAsync(string login, string password)
        {
            try
            {
                OperationStatusInfo operationStatusInfo = await this.systemSettings.Connection.InvokeAsync <OperationStatusInfo>("enter", login, password);

                if (operationStatusInfo.OperationStatus == OperationStatus.Done)
                {
                    string  attachedObjectText = operationStatusInfo.AttachedObject.ToString();
                    UserDTO userDTO            = JsonConvert.DeserializeObject <UserDTO>(attachedObjectText);

                    return(userDTO);
                }
                else
                {
                    throw new Exception(operationStatusInfo.AttachedInfo);
                }
            }
            catch (InvalidOperationException ex)
            {
                this.isConnected = false;
                throw new Exception("Enter is not executed. Reason: Connection to server is absent now. Please, reconnect later", ex);
            }
            catch (Exception ex)
            {
                throw new Exception("Enter is not executed. Reason: " + ex.Message, ex);
            }
        }
        public async Task <List <Provider> > ShowProvidersAsync()
        {
            try
            {
                OperationStatusInfo operationStatusInfo = await this.systemSettings.Connection.InvokeAsync <OperationStatusInfo>("ShowProviders");

                if (operationStatusInfo.OperationStatus == OperationStatus.Done)
                {
                    string          attachedObjectText = operationStatusInfo.AttachedObject.ToString();
                    List <Provider> providers          = JsonConvert.DeserializeObject <List <Provider> >(attachedObjectText);

                    return(providers);
                }
                else
                {
                    throw new Exception(operationStatusInfo.AttachedInfo);
                }
            }
            catch (InvalidOperationException ex)
            {
                frontServiceClient.IsConnected = false;
                throw new Exception("Showing is not executed. Reason: Connection to server is absent now. Please, reconnect later", ex);
            }
            catch (Exception ex)
            {
                throw new Exception("Showing is not executed. Reason: " + ex.Message, ex);
            }
        }
        public async Task <List <Sale> > ShowSaleByClassAsync(Class class_, DateTime sinceDate, DateTime toDate)
        {
            try
            {
                OperationStatusInfo operationStatusInfo = await this.systemSettings.Connection.InvokeAsync <OperationStatusInfo>("ShowSalesByClass", class_, sinceDate, toDate);

                if (operationStatusInfo.OperationStatus == OperationStatus.Done)
                {
                    string      attachedObjectText = operationStatusInfo.AttachedObject.ToString();
                    List <Sale> sales = JsonConvert.DeserializeObject <List <Sale> >(attachedObjectText);

                    return(sales);
                }
                else
                {
                    throw new Exception(operationStatusInfo.AttachedInfo);
                }
            }
            catch (InvalidOperationException ex)
            {
                frontServiceClient.IsConnected = false;
                throw new Exception("Showing is not executed. Reason: Connection to server is absent now. Please, reconnect later", ex);
            }
            catch (Exception ex)
            {
                throw new Exception("Showing is not executed. Reason: " + ex.Message, ex);
            }
        }
Example #13
0
        public async Task <AccountDTO> ShowAccountAsync(int idUser)
        {
            try
            {
                OperationStatusInfo operationStatusInfo = await this.systemSettings.Connection.InvokeAsync <OperationStatusInfo>("ShowAccount", idUser);

                if (operationStatusInfo.OperationStatus == OperationStatus.Done)
                {
                    string     attachedObjectText = operationStatusInfo.AttachedObject.ToString();
                    AccountDTO accountDTO         = JsonConvert.DeserializeObject <AccountDTO>(attachedObjectText);

                    return(accountDTO);
                }
                else
                {
                    throw new Exception(operationStatusInfo.AttachedInfo);
                }
            }
            catch (InvalidOperationException ex)
            {
                this.isConnected = false;
                throw new Exception("Showing is not executed. Reason: Connection to server is absent now. Please, reconnect later", ex);
            }
            catch (Exception ex)
            {
                throw new Exception("Showing is not executed. Reason: " + ex.Message, ex);
            }
        }
        public async Task <NoteDTO> EditNote(NoteDTO note)
        {
            try
            {
                this.cts = new CancellationTokenSource(this.serviceEnvironment.OperationTimeout);

                var paramsToSend = new object[] { note };

                OperationStatusInfo operationStatusInfo =
                    await this.serviceEnvironment.Connection.InvokeCoreAsync <OperationStatusInfo>("editNoteById", paramsToSend, this.cts.Token);

                if (operationStatusInfo.OperationStatus == OperationStatus.Done)
                {
                    string  attachedObjectText = operationStatusInfo.AttachedObject.ToString();
                    NoteDTO newNote            = JsonConvert.DeserializeObject <NoteDTO>(attachedObjectText);
                    return(newNote);
                }
                else
                {
                    throw new Exception(operationStatusInfo.AttachedInfo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{ex.Message}", ex);
            }
        }
        public async Task <UserDTO> UpdateUserAsync(UserDTO user)
        {
            try
            {
                this.cts = new CancellationTokenSource(this.serviceEnvironment.OperationTimeout);

                OperationStatusInfo operationStatusInfo =
                    await this.serviceEnvironment.Connection.InvokeCoreAsync <OperationStatusInfo>("UpdateUser", new object[] { user }, this.cts.Token);

                if (operationStatusInfo.OperationStatus == OperationStatus.Done)
                {
                    string  attachedObjectText = operationStatusInfo.AttachedObject.ToString();
                    UserDTO newUser            = JsonConvert.DeserializeObject <UserDTO>(attachedObjectText);
                    return(newUser);
                }
                else
                {
                    throw new Exception(operationStatusInfo.AttachedInfo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{ex.Message}", ex);
            }
        }
Example #16
0
        public async Task <OperationStatusInfo> UpdateAccount(object updatedAccount)
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);

                string attachedObjectText = updatedAccount.ToString();
                Account newAccount = JsonConvert.DeserializeObject <Account>(attachedObjectText);
                EditAccountRequest editAccountRequest = new EditAccountRequest(newAccount.Id, newAccount.LastName, newAccount.FirstName, newAccount.SecondName, newAccount.Photo);

                try
                {
                    EditAccountResponse editAccountResponse = hubController.UseCaseFactory.CreateEditAccountUseCase().Execute(editAccountRequest);
                    AccountDTO accountDTO = hubController.TransformAccount(editAccountResponse.Account);
                    operationStatusInfo.AttachedObject = accountDTO;
                    operationStatusInfo.AttachedInfo = "Account is updated!";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #17
0
        public async Task <OperationStatusInfo> Login(string login, string password)
        {
            return(await Task.Run(() =>
            {
                logger.Info($"Client {this.GetIpAddress()} entered Login method with params l:{login} p:{password}");

                var operationStatusInfo = new OperationStatusInfo(OperationStatus.Done);
                var enterRequest = new EnterRequestEvent(login, password);

                try
                {
                    var response =
                        this.useCaseFactory.Create <IUseCase <EnterRequestEvent, EnterResponseEvent> >().Execute(enterRequest);

                    operationStatusInfo.AttachedObject = response.UserDTO;

                    return operationStatusInfo;
                }
                catch (Exception ex)
                {
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #18
0
        public async Task <OperationStatusInfo> AddNotes(object addedNotes)
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);

                string attachedObjectText = addedNotes.ToString();
                Notes newNotes = JsonConvert.DeserializeObject <Notes>(attachedObjectText);
                AddNotesRequest addNotesRequest = new AddNotesRequest(newNotes.Topic, newNotes.Text, newNotes.Date, newNotes.Image, newNotes.IdAccount);

                try
                {
                    AddNotesResponse addNotesResponse = hubController.UseCaseFactory.CreateAddNotesUseCase().Execute(addNotesRequest);
                    List <NotesDTO> notesDTO = hubController.TransformNotes(addNotesResponse.Notes);
                    operationStatusInfo.AttachedObject = notesDTO;
                    operationStatusInfo.AttachedInfo = "Notes are added!";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Example #19
0
        public async Task <OperationStatusInfo> UpdateProject(Project project)
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);
                UpdateProjectRequestEvent request = new UpdateProjectRequestEvent(project);

                try
                {
                    UpdateProjectResponseEvent response =
                        _hubEnvironment.UseCaseFactory.Create <IUseCase <UpdateProjectRequestEvent, UpdateProjectResponseEvent> >().Execute(request);

                    operationStatusInfo.AttachedObject = response.Status;

                    return operationStatusInfo;
                }
                catch (Exception ex)
                {
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
        public IActionResult CreateProject(CreateProjectModel createProjectModel)
        {
            Project project = createProjectModel.Project;

            project.Manager = new Employee()
            {
                Id = createProjectModel.EmployeeId
            };
            project.Customer = new Customer()
            {
                Id = createProjectModel.CustomerId
            };
            project.Team = new Team()
            {
                Id = createProjectModel.TeamId
            };

            OperationStatusInfo operationStatusInfo = _hubEnvironment.ServerHubConnector.CreateProject(project).Result;

            if (operationStatusInfo.OperationStatus == OperationStatus.Done)
            {
                return(RedirectToAction("ProjectList"));
            }
            else
            {
                return(CreateProjectPage());
            }
        }
        public IActionResult CreateEmployee(CreateEmployeeModel createEmployeeModel)
        {
            Employee employee = createEmployeeModel.Employee;

            employee.Account = new Account()
            {
                Id = createEmployeeModel.AccountId
            };
            employee.Team = new Team()
            {
                Id = createEmployeeModel.TeamId
            };
            employee.DateOfEmployment = DateTime.Now;

            OperationStatusInfo operationStatusInfo = _hubEnvironment.ServerHubConnector.CreateEmployee(employee).Result;

            if (operationStatusInfo.OperationStatus == OperationStatus.Done)
            {
                return(RedirectToAction("EmployeeList"));
            }
            else
            {
                return(CreateEmployeePage());
            }
        }
        public async Task <List <UserDTO> > GetAllUsersAsync()
        {
            try
            {
                this.cts = new CancellationTokenSource(this.serviceEnvironment.OperationTimeout);

                OperationStatusInfo operationStatusInfo =
                    await this.serviceEnvironment.Connection.InvokeAsync <OperationStatusInfo>("GetAllUsers", this.cts.Token);

                if (operationStatusInfo.OperationStatus == OperationStatus.Done)
                {
                    string         attachedObjectText = operationStatusInfo.AttachedObject.ToString();
                    List <UserDTO> users = JsonConvert.DeserializeObject <List <UserDTO> >(attachedObjectText);
                    return(users);
                }
                else
                {
                    throw new Exception(operationStatusInfo.AttachedInfo);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{ex.Message}", ex);
            }
        }
 public async Task AddProductGoods(Product product, ArrivedGoods arrivedGoods)
 {
     try
     {
         operationStatusInfo = await this.frontServiceClient.AddProductGoodsAsync(product, arrivedGoods);
     }
     catch (Exception ex)
     {
         this.ex = ex;
     }
 }
Example #24
0
 public async Task AddSale(Sale sale)
 {
     try
     {
         operationStatusInfo = await this.frontServiceClient.AddSaleAsync(sale);
     }
     catch (Exception ex)
     {
         this.ex = ex;
     }
 }
Example #25
0
 public async Task EditAccount(int id, string lastName, string firstName, string secondName, int idUser)
 {
     try
     {
         AccountDTO accountDTO = new AccountDTO(id, lastName, firstName, secondName, idUser);
         operationStatusInfo = await this.mainClient.UpdateAccountAsync(accountDTO);
     }
     catch (Exception ex)
     {
         this.ex = ex;
     }
 }
Example #26
0
 public async Task EditNotes(int id, string topic, string text, DateTime dateTime, byte[] image, int idAccount)
 {
     try
     {
         NotesDTO notesDTO = new NotesDTO(id, topic, text, dateTime, image, idAccount);
         operationStatusInfo = await this.mainClient.UpdateNotesAsync(notesDTO);
     }
     catch (Exception ex)
     {
         this.ex = ex;
     }
 }
Example #27
0
        public IActionResult CreateAccount(CreateAccountModel createAccountModel)
        {
            OperationStatusInfo operationStatusInfo = _hubEnvironment.ServerHubConnector.CreateAccount(createAccountModel.Account).Result;

            if (operationStatusInfo.OperationStatus == OperationStatus.Done)
            {
                return(RedirectToAction("AccountList"));
            }
            else
            {
                return(View("CreateAccountPage", new CreateAccountModel(createAccountModel.Account)));
            }
        }
        public IActionResult EmployeeList()
        {
            OperationStatusInfo op = _hubEnvironment.ServerHubConnector.GetAllEmployee().Result;

            if (op.OperationStatus == OperationStatus.Done)
            {
                List <Employee> employees = JsonConvert.DeserializeObject <IEnumerable <Employee> >(op.AttachedObject.ToString()).ToList();

                return(View(new GetAllEmployeeModelSuccess(employees)));
            }

            return(View("ErrorLoadList", new GetAllEmployeeModelFailed(op)));
        }
Example #29
0
        public IActionResult AccountList()
        {
            OperationStatusInfo op = _hubEnvironment.ServerHubConnector.GetAllAccount().Result;

            if (op.OperationStatus == OperationStatus.Done)
            {
                List <Account> account = JsonConvert.DeserializeObject <IEnumerable <Account> >(op.AttachedObject.ToString()).ToList();

                return(View(new GetAllAccountModelSuccess(account)));
            }

            return(View("ErrorLoadList", new GetAllAccountModelFailed(op)));
        }
        public IActionResult TaskList()
        {
            OperationStatusInfo op = _hubEnvironment.ServerHubConnector.GetAllProjectTask().Result;

            if (op.OperationStatus == OperationStatus.Done)
            {
                List <ProjectTask> projectTasks = JsonConvert.DeserializeObject <IEnumerable <ProjectTask> >(op.AttachedObject.ToString()).ToList();

                return(View(new GetAllTaskModelSuccess(projectTasks)));
            }

            return(View("ErrorLoadList", new GetAllTaskModelFailed(op)));
        }