public async Task <ISingleResponse <QuestionDTO> > AddQuestionAsync(string questionText, string[] possibleAnswers, int[] correctAnswers, int testId) { List <int> tempList = new List <int>(correctAnswers); var response = new SingleResponse <QuestionDTO>(); var tempQuestion = new QuestionDTO() { QuestionText = questionText, PossibleAnswers = possibleAnswers, Answer = tempList, TestId = testId }; using (var transaction = await _evalUOW.StartTransaction()) { try { var tempq = await _evalUOW.Questions.Add(_mapper.MapDTOQuestion(tempQuestion)); await _evalUOW.SaveAsync(); response.Model = _mapper.MapQuestion(tempq); transaction.Commit(); } catch (Exception ex) { response.SetError(nameof(AddTestAsync), ex); } } return(response); }
public async Task <ISingleResponse <ServiceEnvironmentStatusLog> > CreateServiceEnvironmentStatusLogAsync(ServiceEnvironmentStatusLog entity, int?serviceEnvironmentID) { Logger?.LogDebug("'{0}' has been invoked", nameof(CreateServiceEnvironmentStatusLogAsync)); var response = new SingleResponse <ServiceEnvironmentStatusLog>(); using (var txn = await DbContext.Database.BeginTransactionAsync()) { try { var serviceEnvStatus = await DbContext.GetByServiceEnvironmentAsync(new ServiceEnvironment(serviceEnvironmentID)); if (serviceEnvStatus == null) { serviceEnvStatus = new ServiceEnvironmentStatus { ServiceEnvironmentID = serviceEnvironmentID, Success = entity.Success, WatchCount = 1, LastWatch = DateTime.Now }; DbContext.ServiceEnvironmentStatuses.Add(serviceEnvStatus); await DbContext.SaveChangesAsync(); Logger?.LogInformation("The status for service environment was saved successfully"); } else { serviceEnvStatus.Success = entity.Success; serviceEnvStatus.WatchCount += 1; serviceEnvStatus.LastWatch = DateTime.Now; Logger?.LogInformation("The status for service environment was updated successfully"); } entity.ServiceEnvironmentStatusID = serviceEnvStatus.ServiceEnvironmentStatusID; entity.Date = DateTime.Now; DbContext.ServiceEnvironmentStatusLogs.Add(entity); await DbContext.SaveChangesAsync(); Logger?.LogInformation("The status details for service environment was created successfully"); txn.Commit(); response.Model = entity; } catch (Exception ex) { txn.Rollback(); response.SetError(Logger, nameof(CreateServiceEnvironmentStatusLogAsync), ex); } } return(response); }
public async Task <ISingleResponse <CategoryModel> > RemoveCategoryAsync(int CategoryID) { Logger?.Info(CreateInvokedMethodLog(MethodBase.GetCurrentMethod().ReflectedType.FullName)); var response = new SingleResponse <CategoryModel>(); try { // Retrieve Category by id Category Category = await CategoryRepository.GetByIDAsync(CategoryID); if (Category == null) { throw new DatabaseException("Category record not found."); } await CategoryRepository.DeleteAsync(Category); response.Model = Mapper.Map <CategoryModel>(Category); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <ISingleResponse <ResultDTO> > AddResultForTestAsync(int testId, string userName, int result) { var response = new SingleResponse <ResultDTO>(); var tempResult = new Result() { TestId = testId, UserName = userName, TestResult = result }; using (var transaction = await _evalUOW.StartTransaction()) { try { if (result < 0 || result > 100) { throw new InvalidResultException("Result cant be less than zero or more than 100"); } tempResult = await _evalUOW.Results.Add(tempResult); await _evalUOW.SaveAsync(); response.Model = _mapper.MapResult(tempResult); transaction.Commit(); } catch (Exception ex) { response.SetError(nameof(AddResultForTestAsync), ex); } } return(response); }
public async Task <ISingleResponse <ProductModel> > AddProductAsync(ProductModel details) { var response = new SingleResponse <ProductModel>(); using (var transaction = DbContext.Database.BeginTransaction()) { try { var product = Mapper.Map <Product>(details); await ProductRepository.AddAsync(product); transaction.Commit(); response.Model = Mapper.Map <ProductModel>(product); } catch (Exception ex) { transaction.Rollback(); response.SetError(ex, Logger); } } return(response); }
public async Task <ISingleResponse <ProductModel> > RemoveProductAsync(int productID) { Logger?.Info(CreateInvokedMethodLog(MethodBase.GetCurrentMethod().ReflectedType.FullName)); var response = new SingleResponse <ProductModel>(); try { // Retrieve product by id Product product = await ProductRepository.GetByIDAsync(productID); if (product == null) { throw new DatabaseException("Product record not found."); } await ProductRepository.DeleteAsync(product); response.Model = Mapper.Map <ProductModel>(product); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <ISingleResponse <UserModel> > RemoveUserAsync(int userID) { Logger.Info(CreateInvokedMethodLog(MethodBase.GetCurrentMethod().ReflectedType.FullName)); var response = new SingleResponse <UserModel>(); try { // Retrieve user by id User user = await _userRepository.GetByIDAsync(userID); if (user == null) { throw new DatabaseException("User record not found."); } await _userRepository.DeleteAsync(user); response.Model = Mapper.Map <UserModel>(user); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <IActionResult> Login([FromBody] vmLoginUserRequest loggingUser) { var loginResponse = new SingleResponse <vmAuthorizedUserResponse>(); try { var existedUserResponse = await _commonService.GetSingleUserForLoginAsync(loggingUser.Email); // if User does not exist or authentication fails if (existedUserResponse.Model == null || existedUserResponse.Model.UserID == 0 || !_passwordHasher.VerifyIdentityV3Hash(loggingUser.Password, existedUserResponse.Model.Password)) { throw new FamilyHubException(string.Format(CommonMessageDisplays.FailedAuthenticationMessage)); } else { // otherwise assign token and refreshtoken loginResponse.Model = await _tokenService.AssignTokenToLoginUserAsync(existedUserResponse.Model); loginResponse.Message = ResponseMessageDisplay.Success; } } catch (Exception ex) { loginResponse.SetError(ex); } return(loginResponse.ToHttpResponse()); }
public async Task <ISingleResponse <RoleModel> > RemoveRoleAsync(int roleID) { Logger.Info(CreateInvokedMethodLog(MethodBase.GetCurrentMethod().ReflectedType.FullName)); var response = new SingleResponse <RoleModel>(); try { // Retrieve user by id Role role = await _roleRepository.GetByIDAsync(roleID); if (role == null) { throw new DatabaseException("User record not found."); } //await UserCredentialRepository.DeleteAsync(user.UserCredential); await _roleRepository.DeleteAsync(role); response.Model = Mapper.Map <RoleModel>(role); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <ISingleResponse <Product> > CreateProductAsync(Product entity) { Logger?.LogInformation("'{0}' has been invoked", nameof(CreateProductAsync)); var response = new SingleResponse <Product>(); try { // Set default values entity.Stocks = 0; entity.Discontinued = false; // Set creation info DbContext.Add(entity, UserInfo); // Save product await DbContext.SaveChangesAsync(); response.Model = entity; } catch (Exception ex) { response.SetError(Logger, nameof(CreateProductAsync), ex); } return(response); }
public async Task <ISingleResponse <UserModel> > AddUserAsync(UserModel details) { Logger.Info(CreateInvokedMethodLog(MethodBase.GetCurrentMethod().ReflectedType.FullName)); var response = new SingleResponse <UserModel>(); using (var transaction = DbContext.Database.BeginTransaction()) { try { var user = Mapper.Map <User>(details); await _userRepository.AddAsync(user); var userCredential = Mapper.Map <UserCredential>(details); userCredential.User = user; await _userCredentialRepository.AddAsync(userCredential); transaction.Commit(); response.Model = Mapper.Map <UserModel>(user); } catch (Exception ex) { transaction.Rollback(); response.SetError(ex, Logger); } } return(response); }
public async Task <ISingleResponse <CreateOrderRequest> > GetCreateOrderRequestAsync() { Logger?.LogDebug("{0} has been invoked", nameof(GetCreateOrderRequestAsync)); var response = new SingleResponse <CreateOrderRequest>(); try { // Retrieve customers list response.Model.Customers = await SalesRepository.GetCustomers().ToListAsync(); // Retrieve employees list response.Model.Employees = await HumanResourcesRepository.GetEmployees().ToListAsync(); // Retrieve shippers list response.Model.Shippers = await SalesRepository.GetShippers().ToListAsync(); // Retrieve products list response.Model.Products = await ProductionRepository.GetProducts().ToListAsync(); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <ISingleResponse <Order> > RemoveOrderAsync(Int32 id) { Logger?.LogDebug("{0} has been invoked", nameof(RemoveOrderAsync)); var response = new SingleResponse <Order>(); try { // Retrieve order by id response.Model = await SalesRepository .GetOrderAsync(new Order(id)); if (response.Model != null) { if (response.Model.OrderDetails.Count > 0) { // Restrict remove operation for orders with details throw new ForeignKeyDependencyException(String.Format(SalesDisplays.RemoveOrderExceptionMessage, id)); } // Delete order await SalesRepository.DeleteOrderAsync(response.Model); Logger?.LogInformation(SalesDisplays.DeleteOrderMessage); } } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <ISingleResponse <RoleModel> > AddRoleResourcesAsync(RoleModel role, ICollection <ResourceModel> resources) { Logger.Info(CreateInvokedMethodLog(MethodBase.GetCurrentMethod().ReflectedType.FullName)); var response = new SingleResponse <RoleModel>(); using (var transaction = DbContext.Database.BeginTransaction()) { try { foreach (var res in resources) { await _roleResourceRepository.AddAsync(new JRoleResource { RoleID = role.ID, ResourceID = res.ID }); } transaction.Commit(); var roleResponse = await DbContext.Set <Role>().EagerWhere(x => x.RoleResources, m => m.ID == role.ID).FirstOrDefaultAsync(); response.Model = Mapper.Map <RoleModel>(roleResponse); } catch (Exception ex) { transaction.Rollback(); response.SetError(ex, Logger); } } return(response); }
public async Task <ISingleResponse <ResourceModel> > UpdateResourceAsync(ResourceModel updates) { Logger.Info(CreateInvokedMethodLog(MethodBase.GetCurrentMethod().ReflectedType.FullName)); var response = new SingleResponse <ResourceModel>(); using (var transaction = DbContext.Database.BeginTransaction()) { try { Resource resource = await _resourceRepository.GetByIDAsync(updates.ID); if (resource == null) { throw new DatabaseException("Resource record not found."); } Mapper.Map(updates, resource); await _resourceRepository.UpdateAsync(resource); transaction.Commit(); response.Model = Mapper.Map <ResourceModel>(resource); } catch (Exception ex) { transaction.Rollback(); response.SetError(ex, Logger); } } return(response); }
public async Task <ISingleResponse <vmTransactionPrepareRequest> > PrepareTransactionRelatedRequestAsync(int currentUid) { var response = new SingleResponse <vmTransactionPrepareRequest>(); try { // Retrieve PaymentMethods list response.Model.PaymentMethods = await PaymentMethodRepository.GetListPaymentMethodAsync(); // Retrieve PaymentPayors list response.Model.PaymentPayors = await PaymentPayorRepository.GetListPaymentPayorAsync(currentUid); // Retrieve TransactionCategorys list response.Model.TransactionCategorys = await TransactionCategoryRepository.GetListTransactionCategoryAsync(); // Retrieve TransactionTypes list response.Model.TransactionTypes = await TransactionTypeRepository.GetListTransactionTypeAsync(); } catch (Exception ex) { response.SetError(ex); } return(response); }
public async Task <ISingleResponse <TestDTO> > UpdateTestAsync(int id, string testName) { var response = new SingleResponse <TestDTO>(); Test test = new Test { TestId = id, TestName = testName }; using (var transaction = await _evalUOW.StartTransaction()) { try { _evalUOW.Tests.Update(test); await _evalUOW.SaveAsync(); response.Model = _mapper.MapTest(test); transaction.Commit(); } catch (Exception ex) { response.SetError(nameof(AddTestAsync), ex); } } return(response); }
public async Task <ISingleResponse <UsuarioZiPago> > AutenticarUsuarioZiPagoAsync(Logger logger, UsuarioZiPago entidad) { var response = new SingleResponse <UsuarioZiPago>(); logger.Info("[{0}] | UsuarioZiPago: [{1}] | Inicio.", nameof(AutenticarUsuarioZiPagoAsync), entidad.Clave1); try { response.Model = await DbContext.ObtenerUsuarioZiPagoAsync(entidad.Clave1); if (response.Model != null && (Criptografia.Desencriptar(response.Model.Clave2.Trim()) == Criptografia.Desencriptar(entidad.Clave2))) { response.Model.Clave2 = ""; response.Mensaje = "1"; } else { response.Model = null; response.Mensaje = Constantes.strMensajeUsuarioIncorrecto; } logger.Info("[{0}] | UsuarioZiPago: [{1}] | Mensaje: [{2}].", nameof(AutenticarUsuarioZiPagoAsync), entidad.Clave1, response.Mensaje); } catch (Exception ex) { response.Model = null; response.SetError(logger, nameof(AutenticarUsuarioZiPagoAsync), nameof(UsuarioZiPago), ex); } return(response); }
public async Task <ISingleResponse <TestDTO> > AddTestAsync(string testName) { var response = new SingleResponse <TestDTO>(); var tempTest = new Test() { TestName = testName, }; using (var transaction = await _evalUOW.StartTransaction()) { try { var tempt = await _evalUOW.Tests.Add(tempTest); await _evalUOW.SaveAsync(); response.Model = _mapper.MapTest(tempt); transaction.Commit(); } catch (Exception ex) { response.SetError(nameof(AddTestAsync), ex); } } return(response); }
public async Task <ISingleResponse <QuestionDTO> > UpdateQuestionAsync(int id, string questionText, string[] PossibleAnswers, int[] correctAnswers, int testId) { var response = new SingleResponse <QuestionDTO>(); List <int> tempList = new List <int>(correctAnswers); QuestionDTO questionDTO = new QuestionDTO { QuestionId = id, QuestionText = questionText, TestId = testId, PossibleAnswers = PossibleAnswers, Answer = tempList }; Question question = _mapper.MapDTOQuestion(questionDTO); using (var transaction = await _evalUOW.StartTransaction()) { try { _evalUOW.Questions.Update(question); await _evalUOW.SaveAsync(); response.Model = _mapper.MapQuestion(question); transaction.Commit(); } catch (Exception ex) { response.SetError(nameof(AddTestAsync), ex); } } return(response); }
public async Task <ISingleResponse <UserModel> > AddUserRoleAsync(int userID, int roleID) { Logger.Info(CreateInvokedMethodLog(MethodBase.GetCurrentMethod().ReflectedType.FullName)); var response = new SingleResponse <UserModel>(); using (var transaction = DbContext.Database.BeginTransaction()) { try { await _userRoleRepository.AddAsync(new JUserRole { UserId = userID, RoleId = roleID }); transaction.Commit(); var userResponse = await DbContext.Set <User>().EagerWhere(x => x.UserRoles, m => m.ID == userID).FirstOrDefaultAsync(); response.Model = Mapper.Map <UserModel>(userResponse); } catch (Exception ex) { transaction.Rollback(); response.SetError(ex, Logger); } } return(response); }
public async Task <ISingleResponse <vmMemberContactDetailResponse> > AddMemberContactAsync(vmMemberContactDetailRequest newMemberContactRequest) { var response = new SingleResponse <vmMemberContactDetailResponse>(); try { var newMemberContact = _mapper.Map <vmMemberContactDetailRequest, MemberContact>(newMemberContactRequest); // Create new payment payor await MemberContactRepository.AddMemberContactAsync(newMemberContact); // Fetch complete object from database newMemberContact = await MemberContactRepository.GetSingleMemberContactByIDAsync(newMemberContact.MemberContactID); // Convert from Domain Model to View Model var newMemberContactResponse = _mapper.Map <MemberContact, vmMemberContactDetailResponse>(newMemberContact); response.Model = newMemberContactResponse; response.Message = ResponseMessageDisplay.Success; } catch (Exception ex) { response.SetError(ex); } return(response); }
public async Task <ISingleResponse <OrderHeader> > CloneOrderAsync(long id) { Logger?.LogDebug("'{0}' has been invoked", nameof(CloneOrderAsync)); var response = new SingleResponse <OrderHeader>(); try { // Retrieve order by id var entity = await DbContext.GetOrderAsync(new OrderHeader(id)); if (entity == null) { return(response); } // Create a new instance for order and set values from existing order response.Model = new OrderHeader { ID = entity.ID, OrderDate = entity.OrderDate, CustomerID = entity.CustomerID, EmployeeID = entity.EmployeeID, ShipperID = entity.ShipperID, Total = entity.Total, Comments = entity.Comments }; if (entity.OrderDetails?.Count > 0) { response.Model.OrderDetails = new Collection <OrderDetail>(); foreach (var detail in entity.OrderDetails) { // Add order detail clone to collection response.Model.OrderDetails.Add(new OrderDetail { ProductID = detail.ProductID, ProductName = detail.ProductName, UnitPrice = detail.UnitPrice, Quantity = detail.Quantity, Total = detail.Total }); } } } catch (Exception ex) { response.SetError(Logger, nameof(CloneOrderAsync), ex); } return(response); }
public async Task <ISingleResponse <Order> > CloneOrderAsync(int id) { Logger?.LogDebug("{0} has been invoked", nameof(CloneOrderAsync)); var response = new SingleResponse <Order>(); try { // Retrieve order by id var entity = await SalesRepository .GetOrderAsync(new Order(id)); if (entity != null) { // Init a new instance for order // Set values from existing order response.Model = new Order { OrderID = entity.OrderID, OrderDate = entity.OrderDate, CustomerID = entity.CustomerID, EmployeeID = entity.EmployeeID, ShipperID = entity.ShipperID, Total = entity.Total, Comments = entity.Comments }; if (entity.OrderDetails != null && entity.OrderDetails.Count > 0) { foreach (var detail in entity.OrderDetails) { // Add order detail clone to collection response.Model.OrderDetails.Add(new OrderDetail { ProductID = detail.ProductID, ProductName = detail.ProductName, UnitPrice = detail.UnitPrice, Quantity = detail.Quantity, Total = detail.Total }); } } } } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <ISingleResponse <Employee> > GetEmployeeAsync(Employee entity) { var response = new SingleResponse <Employee>(); try { response.Model = await HumanResourcesRepository.GetEmployeeAsync(entity); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <ISingleResponse <User> > GetUsersByIDAsync(int userID) { Logger?.LogInformation(CreateInvokedMethodLog(MethodBase.GetCurrentMethod().ReflectedType.FullName)); var response = new SingleResponse <User> (); try { response.Model = await UserRepository.GetByIDAsync(userID); } catch (Exception ex) { response.SetError(ex, Logger); } return(response); }
public async Task <ISingleResponse <User> > UpdateUserRefreshTokenAsync(User loginUser) { var response = new SingleResponse <User>(); try { await UserRepository.UpdateUserAsync(loginUser); } catch (Exception ex) { response.SetError(ex); } return(response); }
public async Task <ISingleResponse <User> > GetUserContactAddressAsync(int userId) { var response = new SingleResponse <User>(); try { response.Model = await UserRepository .GetSingleUserInfoAsync(new User(userId), withContact : true); } catch (Exception ex) { response.SetError(ex); } return(response); }
public async Task <ISingleResponse <vmMemberContactDetailResponse> > UpdateMemberContactAsync(int memberContactId, vmMemberContactDetailRequest updateMemberContactRequest) { var response = new SingleResponse <vmMemberContactDetailResponse>(); try { var duplicateMemberContact = await MemberContactRepository.GetSingleMemberContactByNameAsync($"{updateMemberContactRequest.FirstName} {updateMemberContactRequest.LastName}"); if (duplicateMemberContact != null && duplicateMemberContact.MemberContactID != memberContactId) { response.Message = ResponseMessageDisplay.Duplicate; // Throw exception if duplicate existed throw new FamilyHubException(string.Format(MemberMessageDisplay.MemberContactAlreadyExistedMessage, $"{updateMemberContactRequest.FirstName} {updateMemberContactRequest.LastName}")); } else { var memberContactFromDB = await MemberContactRepository.GetSingleMemberContactByIDAsync(memberContactId); if (memberContactFromDB == null) { response.Message = ResponseMessageDisplay.NotFound; // Throw exception if duplicate existed throw new FamilyHubException(string.Format(MemberMessageDisplay.MemberContactNotFoundMessage)); } else { _mapper.Map <vmMemberContactDetailRequest, MemberContact>(updateMemberContactRequest, memberContactFromDB); await MemberContactRepository.UpdateMemberContactAsync(memberContactFromDB); // Fetch complete object from database memberContactFromDB = await MemberContactRepository.GetSingleMemberContactByIDAsync(memberContactFromDB.MemberContactID); // Convert from Domain Model to View Model var newMemberContactResponse = _mapper.Map <MemberContact, vmMemberContactDetailResponse>(memberContactFromDB); response.Model = newMemberContactResponse; response.Message = ResponseMessageDisplay.Success; } } } catch (Exception ex) { response.SetError(ex); } return(response); }
public async Task <ISingleResponse <Employee> > GetEmployeeAsync(Employee entity) { Logger?.LogInformation("{0} has been invoked", nameof(GetEmployeeAsync)); var response = new SingleResponse <Employee>(); try { response.Model = await DbContext.GetEmployeeAsync(entity); } catch (Exception ex) { response.SetError(Logger, nameof(GetEmployeeAsync), ex); } return(response); }