public string ClothesGeneration(string theResult, string city, int id) { DataBaseRepository dataBase = new DataBaseRepository(); List <string> categoriesInList = new List <string>(); string[] categories = theResult.Split(','); for (int i = 0; i < categories.Length; i++) { categoriesInList.Add(categories[i]); } string finalResult = ""; for (int i = 0; i < categoriesInList.Count - 1; i++) { var client = new RestClient("https://apidojo-hm-hennes-mauritz-v1.p.rapidapi.com/products/list?categories=" + categoriesInList[i] + "&country=us&lang=en¤tpage=0&pagesize=1"); var request = new RestRequest(Method.GET); request.AddHeader("x-rapidapi-host", "apidojo-hm-hennes-mauritz-v1.p.rapidapi.com"); request.AddHeader("x-rapidapi-key", "9a5793a005mshb2a37a462d5ba89p10baacjsn1596887f9ad7"); IRestResponse response = client.Execute(request); JObject json = JObject.Parse(response.Content); string firstsplit = Convert.ToString(json); string[] firstsplit1 = firstsplit.Split(new string[] { "\"name\":" }, StringSplitOptions.None); string[] secondsplit = firstsplit1[1].Split(new string[] { "\"stock\":" }, StringSplitOptions.None); finalResult = finalResult + secondsplit[0]; } dataBase.Insert(id, city, finalResult, categoriesInList.Last()); return(finalResult + "," + categoriesInList.Last()); }
public void Execute(IJobExecutionContext context) { IDataBaseRepository dataBaseRepository = new DataBaseRepository(); IDataBaseLogic dataBaseLogic = new DataBaseLogic(dataBaseRepository); dataBaseLogic.AddUser(); }
private void Login_Click(object sender, RoutedEventArgs e) { if (textBoxLogin.Text == null) { MessageBox.Show("Please, enter your login"); } if (PasswordBox.Password == null) { MessageBox.Show("Please, enter your password"); } if (ifemployer == true) { var t = Employer.Sign(textBoxLogin.Text, DataBaseRepository.GetHash(PasswordBox.Password)); if (t != null) { NavigationService.Navigate(new EmployerAccountPage(repository, t)); } else { MessageBox.Show("Wrong login or password"); } } else { var t = Employee.Sign(textBoxLogin.Text, DataBaseRepository.GetHash(PasswordBox.Password)); if (t != null) { NavigationService.Navigate(new EmployeeAccountPage(repository, t)); } else { MessageBox.Show("Wrong login or password"); } } }
public WedstrijdSecretariaat(DataBaseRepository dataBaseControl) { this.Message = new MessageService(); this.WedstrijdSimulatie = new WedstrijdSimulatie(this); this._dataBaseRepository = dataBaseControl; SetRangLijst(); }
//public static DataBase DDataBase { get; set; } = new DataBase(); //public static DataBaseControl DataBaseController = new DataBaseControl(); /// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; var dbc = new DataBaseRepository(); dbc.MigrateDataBase(); }
private void UpdateAllLists() { WedstrijdSecretariaat ws = new WedstrijdSecretariaat(DataBaseRepository); UpdateList(FilteredTeamList, DataBaseRepository.GetAlleTeams()); UpdateList(FilteredSpelersList, DataBaseRepository.GetAlleSpelers(), "AchterNaam", "VoorNaam"); UpdateList(FilteredCoachesList, DataBaseRepository.GetAlleCoaches(), "AchterNaam", "VoorNaam"); UpdateList(FilteredWedstrijdList, DataBaseRepository.GetAlleWedstrijden()); UpdateList(FilteredRangList, ws.RangLijst, "WedstrijdSaldo", "DoelSaldo", "NaamToString", true); }
//Выход из приложения по нажатию на соответсвующий пункт меню в разделе "Файл" private void ExitTStrMenu_Click(object sender, EventArgs e) { isFormClosingThroughMenuButton = true; DialogResult dialogResult = MessageBox.Show("Хотите ли вы сохранить найденные предприятия?", "Сохранение предприятия", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { DataBaseRepository.Save(foundCompanies, "searchResult.json"); } Close(); }
//сохранение при закрытии формы private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { DataBaseRepository.Save(CompanyCollection.companies); if (!isFormClosingThroughMenuButton) { DialogResult dialogResult = MessageBox.Show("Хотите ли вы сохранить найденные предприятия?", "Сохранение предприятия", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { DataBaseRepository.Save(foundCompanies, "searchResult.json"); } } }
//{ // get // { // return getDatabaseControlFunc?.Invoke(); // } // set // { // setDatabaseControlAction(value); // this.OnPropertyChanged(nameof(DataBaseController)); // } //} //public DataBase dataBase //{ // get // { // return getDatabaseFunc?.Invoke(); // } // set // { // setDatabaseAction(value); // this.OnPropertyChanged(nameof(dataBase)); // } //} public ViewModelDataBase() { // this.dataBase = getDatabaseFunc?.Invoke(); //_dataBase = new ApplicationDBContext(); //DataBaseController = new DataBaseControl(_dataBase); DataBaseRepository = new DataBaseRepository(); // Als de spelers lijst geen elementen bevat seed deze dan if (DataBaseRepository.GetAlleSpelers().Count == 0) { DataBaseRepository.SeedDataBase(); } }
public IdentityService(DataBaseRepository dataBaseRepository, IConfiguration configuration) { this.dataBaseRepository = dataBaseRepository; Configuration = configuration; }
//сохранение документа по клику "Файл", "Сохранить" private void SaveTStrMenu_Click(object sender, EventArgs e) { DataBaseRepository.Save(CompanyCollection.companies); }
public Querys(IHttpContextAccessor httpContext, DataBaseRepository dataBaseRepository) { Name = "Query"; Field <UserType>( "GetCurrentUser", arguments: new QueryArguments( new QueryArgument <DateGraphType> { Name = "CalendarDay", Description = "Selected day" } ), resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); user.ComputedProps = new ComputedProps(); user.ComputedProps.AddPermission(dataBaseRepository.GetPermission(user.Id)); user.ComputedProps.AddTeams(dataBaseRepository.GetUserTeams(user.Id)); System.DateTime?selectedDay = context.GetArgument <System.DateTime?>("CalendarDay"); if (selectedDay.HasValue) { var a = dataBaseRepository.GetTimerHistory(user.Id) .Where(r => r.StartTime.Value.ToShortDateString() == selectedDay.Value.Date.ToShortDateString()); user.ComputedProps.AddTimerHistory(new List <TimerHistory>(a.OfType <TimerHistory>())); } else { user.ComputedProps.AddTimerHistory(dataBaseRepository.GetTimerHistory(user.Id)); } return(user); } ).AuthorizeWith("Authenticated"); Field <ListGraphType <UserType> >( "GetAllUsers", arguments: null, resolve: context => { return(dataBaseRepository.Get()); } ).AuthorizeWith("Manager"); Field <ListGraphType <TeamType> >( "GetTeams", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); return(dataBaseRepository.GetListOfAvailableTeams(user.Id)); }, description: "Get list of available teams." ).AuthorizeWith("Manager"); Field <ListGraphType <TeamType> >( "GetUserTeams", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); return(dataBaseRepository.GetUserTeams(user.Id)); } ).AuthorizeWith("Authenticated"); Field <ListGraphType <UserType> >( "GetTeamUsers", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "TeamId", Description = "Team id." } ), resolve: context => { int teamId = context.GetArgument <int>("TeamId"); return(dataBaseRepository.GetTeamUsers(teamId)); } ).AuthorizeWith("Authenticated"); Field <ListGraphType <StringGraphType> >( "GetAllPermissions", arguments: null, resolve: context => { return(dataBaseRepository.GetAllPermissions()); } ).AuthorizeWith("Manager"); Field <ListGraphType <VacationRequestType> >( "GetCurrentUserRequests", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); int id = user.Id; return(dataBaseRepository.GetUserVacationRequests(user.Id)); } ).AuthorizeWith("Authenticated"); Field <ListGraphType <VacationResponseType> >( "GetVacationRequestInfo", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "RequestID" } ), resolve: context => { int requestId = context.GetArgument <int>("RequestID"); return(dataBaseRepository.GetVacationRequestResponses(requestId)); } ).AuthorizeWith("Authenticated"); Field <ListGraphType <VacationRequestType> >( "GetRequestsForConsideration", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); int id = user.Id; return(dataBaseRepository.GetRequestsForConsideration(id)); } ).AuthorizeWith("Manager"); Field <ListGraphType <VacationRequestType> >( "GetConsideredRequests", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); int id = user.Id; return(dataBaseRepository.GetConsideredRequests(id)); } ).AuthorizeWith("Manager"); FieldAsync <ListGraphType <TimerHistoryType>, IReadOnlyCollection <TimerHistory> >( "GetTimerHistories", resolve: ctx => { return(dataBaseRepository.GetTimerHistory()); }).AuthorizeWith("Authenticated"); Field <UserType>( "GetCurrentUserId", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); return(user); } ).AuthorizeWith("Authenticated"); Field <ListGraphType <UserType> >( "GetUsersOnVacation", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <DateTimeGraphType> > { Name = "Date" } ), resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); user.ComputedProps = new ComputedProps(); user.ComputedProps.AddTeams(dataBaseRepository.GetUserTeams(user.Id)); DateTime DateToCheck = context.GetArgument <DateTime>("Date"); List <User> teammatesOnVacation = new List <User>(); user.ComputedProps.Teams.ForEach((team) => { dataBaseRepository.GetTeamUsers(team.Id).ForEach((user) => { dataBaseRepository.GetUserVacationRequests(user.Id).ToList().ForEach((request) => { if (request.FinishDate >= DateToCheck && request.StartDate <= DateToCheck) { if (teammatesOnVacation.Contains(user)) { return; } teammatesOnVacation.Add(user); } }); }); }); return(teammatesOnVacation); } ).AuthorizeWith("Authenticated"); Field <DecimalGraphType>( "GetAvailableVacationDays", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); user.ComputedProps = new ComputedProps(); user.ComputedProps.AddVacationRequests(dataBaseRepository.GetUserVacationRequests(user.Id).ToList()); DateTime currentDate = DateTime.Now; int vacationDaysSum = user.ComputedProps.VacationRequests .Select(request => (Start: request.StartDate, Finish: request.FinishDate)) //returns only the date pair .Where(date => //selects request the has the same month (date.Finish.Year == currentDate.Year && date.Finish.Month == currentDate.Month) || (date.Start.Year == currentDate.Year && date.Start.Month == currentDate.Month)) .Select(dates => //crops dates to be within the month { var newDates = (Start: dates.Start, Finish: dates.Finish); // makes a copy if (newDates.Start.Month < currentDate.Month) { newDates.Start = new DateTime(currentDate.Year, currentDate.Month, 1); } if (newDates.Finish.Month > currentDate.Month) { newDates.Finish = new DateTime(currentDate.Year, currentDate.Month, DateTime.DaysInMonth(currentDate.Year, currentDate.Month)); } return(newDates); }) .Sum(dates => dates.Finish.DayOfYear - dates.Start.DayOfYear + 1); int availableVacationDaysPerMonth = 2; if (availableVacationDaysPerMonth - vacationDaysSum < 0) { return(0); } return(availableVacationDaysPerMonth - vacationDaysSum); }
public void TestMethod2() { DataBaseRepository repository = new DataBaseRepository(); repository.AddDish(null); }
public Mutations(IdentityService identityService, DataBaseRepository dataBaseRepository, EmailService emailService) { Name = "Mutation"; Field <StringGraphType>( "authentication", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Email", Description = "User email." }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Password", Description = "User password." } ), resolve: context => { string email = context.GetArgument <string>("Email"); string password = context.GetArgument <string>("Password"); return(identityService.Authenticate(email, password)); }, description: "Returns JWT." ); Field <BooleanGraphType>( "createUser", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Name", Description = "User name" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Surname", Description = "User surname" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Email", Description = "User email" }, new QueryArgument <NonNullGraphType <ListGraphType <StringGraphType> > > { Name = "Permissions", Description = "User permisions" }, new QueryArgument <ListGraphType <IntGraphType> > { Name = "Teams", Description = "User teams id" } ), resolve: context => { string email = context.GetArgument <string>("Email"); string name = context.GetArgument <string>("Name"); string surname = context.GetArgument <string>("Surname"); List <string> permissions = context.GetArgument <List <string> >("Permissions"); List <int> teamsId = context.GetArgument <List <int> >("Teams"); string password = Guid.NewGuid().ToString(); User user = dataBaseRepository.CreateUser(name, surname, email, password, permissions, teamsId); if (user.Email != null) { try { emailService.SendEmail(email, password); }catch { return(false); } } return(true); } ).AuthorizeWith("Manager"); Field <BooleanGraphType>( "RemoveUser", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Email", Description = "User email" }), resolve: context => { return(dataBaseRepository.RemoveUser(context.GetArgument <string>("Email"))); } ); Field <ListGraphType <VacationRequestType> >( "addVacationRequest", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "UserId", Description = "User id" }, new QueryArgument <NonNullGraphType <DateGraphType> > { Name = "StartDate", Description = "Vacation start date" }, new QueryArgument <NonNullGraphType <DateGraphType> > { Name = "FinishDate", Description = "Vacation finish date" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Status", Description = "Status of the vacation" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Comment", Description = "Comment of the vacation" } ), resolve: context => { int userId = context.GetArgument <int>("UserId"); DateTime startDate = context.GetArgument <DateTime>("StartDate"); DateTime finishDate = context.GetArgument <DateTime>("FinishDate"); string status = context.GetArgument <string>("Status"); string comment = context.GetArgument <string>("Comment"); return(dataBaseRepository.AddRequest(userId, startDate, finishDate, status, comment)); }, description: "Returns user requests." ).AuthorizeWith("Authenticated"); Field <ListGraphType <VacationRequestType> >( "removeVacationRequest", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "Id", Description = "Vacation request id" } ), resolve: context => { int id = context.GetArgument <int>("Id"); return(dataBaseRepository.RemoveRequest(id)); }, description: "Returns user requests." ).AuthorizeWith("Authenticated"); }
//Constructor public ViewModelFilteredLists() { FilteredRangList = new ObservableCollection <VoetbalTeam>(); FilteredTeamList = new ObservableCollection <VoetbalTeam>(); FilteredSpelersList = new ObservableCollection <Speler>(); FilteredCoachesList = new ObservableCollection <Coach>(); FilteredWedstrijdList = new ObservableCollection <Wedstrijd>(); UpdateAllLists(); var ws = new WedstrijdSecretariaat(DataBaseRepository); FilterChanged += UpdateAllLists; //De DataBaseRepository raist een event als er een wijziging wordt gedaan in de lijsten. Hieronder wordt de bijbehoorende lijst dan geupdatet DataBaseRepository.WedstrijdenGewijzigd += () => UpdateList(FilteredWedstrijdList, DataBaseRepository.GetAlleWedstrijden()); DataBaseRepository.TeamsGewijzigd += () => UpdateList(FilteredTeamList, DataBaseRepository.GetAlleTeams()); DataBaseRepository.SpelersGewijzigd += () => UpdateList(FilteredSpelersList, DataBaseRepository.GetAlleSpelers(), "AchterNaam", "VoorNaam"); DataBaseRepository.CoachesGewijzigd += () => UpdateList(FilteredCoachesList, DataBaseRepository.GetAlleCoaches(), "AchterNaam", "VoorNaam"); DataBaseRepository.DoelpuntenGewijzigd += () => UpdateList(FilteredWedstrijdList, DataBaseRepository.GetAlleWedstrijden()); DataBaseRepository.DoelpuntenGewijzigd += () => UpdateList(FilteredRangList, ws.RangLijst.ToList(), "WedstrijdSaldo", "DoelSaldo", "NaamToString", true); }
//конструктор static CompanyCollection() { companies = DataBaseRepository.Get(); }
public Querys(IHttpContextAccessor httpContext, DataBaseRepository dataBaseRepository) { Name = "Query"; Field<UserType>( "GetCurrentUser", arguments: new QueryArguments( new QueryArgument<DateGraphType> { Name = "CalendarDay", Description = "Selected day" } ), resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); user.ComputedProps = new ComputedProps(); user.ComputedProps.AddPermission(dataBaseRepository.GetPermission(user.Id)); user.ComputedProps.AddTeams(dataBaseRepository.GetUserTeams(user.Id)); System.DateTime? selectedDay = context.GetArgument<System.DateTime?>("CalendarDay"); if (selectedDay.HasValue) { var a = dataBaseRepository.GetTimerHistory(user.Id) .Where(r => r.StartTime.Value.ToShortDateString() == selectedDay.Value.Date.ToShortDateString()); user.ComputedProps.AddTimerHistory(new List<TimerHistory>(a.OfType<TimerHistory>())); } else user.ComputedProps.AddTimerHistory(dataBaseRepository.GetTimerHistory(user.Id)); return user; } ).AuthorizeWith("Authenticated"); Field<ListGraphType<TeamType>>( "GetTeams", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); return dataBaseRepository.GetListOfAvailableTeams(user.Id); }, description: "Get list of available teams." ).AuthorizeWith("Manager"); Field<ListGraphType<TeamType>>( "GetUserTeams", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); return dataBaseRepository.GetUserTeams(user.Id); } ).AuthorizeWith("Authenticated"); Field<ListGraphType<UserType>>( "GetTeamUsers", arguments: new QueryArguments( new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "TeamId", Description = "Team id."} ), resolve: context => { int teamId = context.GetArgument<int>("TeamId"); return dataBaseRepository.GetTeamUsers(teamId); } ).AuthorizeWith("Authenticated"); Field<ListGraphType<StringGraphType>>( "GetAllPermissions", arguments: null, resolve: context => { return dataBaseRepository.GetAllPermissions(); } ).AuthorizeWith("Manager"); Field<ListGraphType<VacationRequestType>>( "GetCurrentUserRequests", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); int id = user.Id; return dataBaseRepository.GetUserRequests(user.Id); } ).AuthorizeWith("Authenticated"); FieldAsync<ListGraphType<TimerHistoryType>, IReadOnlyCollection<TimerHistory>>( "GetTimerHistories", resolve: ctx => { return dataBaseRepository.GetTimerHistory(); }).AuthorizeWith("Authenticated"); Field<UserType>( "GetCurrentUserId", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); return user; } ).AuthorizeWith("Authenticated"); Field<ListGraphType<UserType>>( "GetUsersOnVacation", arguments: new QueryArguments( new QueryArgument<NonNullGraphType<DateTimeGraphType>> { Name="Date" } ), resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); user.ComputedProps = new ComputedProps(); user.ComputedProps.AddTeams(dataBaseRepository.GetUserTeams(user.Id)); DateTime DateToCheck = context.GetArgument<DateTime>("Date"); List<User> teammatesOnVacation = new List<User>(); user.ComputedProps.Teams.ForEach((team) => { dataBaseRepository.GetTeamUsers(team.Id).ForEach((user) => { dataBaseRepository.GetUserRequests(user.Id).ForEach((request) => { if(request.FinishDate >= DateToCheck && request.StartDate <= DateToCheck) { if (teammatesOnVacation.Contains(user)) return; teammatesOnVacation.Add(user); } }); }); }); return teammatesOnVacation; } ).AuthorizeWith("Authenticated"); }
public DatabaseService(DataBaseRepository repository) { _repository = repository; }
public Mutations(IdentityService identityService, DataBaseRepository dataBaseRepository, EmailService emailService, IHttpContextAccessor httpContext) { Name = "Mutation"; Field <StringGraphType>( "authentication", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Email", Description = "User email." }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Password", Description = "User password." } ), resolve: context => { string email = context.GetArgument <string>("Email"); string password = context.GetArgument <string>("Password"); return(identityService.Authenticate(email, password)); }, description: "Returns JWT." ); Field <BooleanGraphType>( "createUser", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Name", Description = "User name" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Surname", Description = "User surname" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Email", Description = "User email" }, new QueryArgument <NonNullGraphType <ListGraphType <StringGraphType> > > { Name = "Permissions", Description = "User permisions" }, new QueryArgument <ListGraphType <IntGraphType> > { Name = "Teams", Description = "User teams id" } ), resolve: context => { string email = context.GetArgument <string>("Email"); string name = context.GetArgument <string>("Name"); string surname = context.GetArgument <string>("Surname"); List <string> permissions = context.GetArgument <List <string> >("Permissions"); List <int> teamsId = context.GetArgument <List <int> >("Teams"); string password = Guid.NewGuid().ToString(); User user = dataBaseRepository.CreateUser(name, surname, email, password, permissions, teamsId); if (user.Email != null) { try { emailService.SendEmail(email, password); }catch { return(false); } } return(true); } ).AuthorizeWith("Manager"); Field <BooleanGraphType>( "RemoveUser", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Email", Description = "User email" }), resolve: context => { return(dataBaseRepository.RemoveUser(context.GetArgument <string>("Email"))); } ); Field <ListGraphType <VacationRequestType> >( "addVacationRequest", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "UserId", Description = "User id" }, new QueryArgument <NonNullGraphType <DateGraphType> > { Name = "StartDate", Description = "Vacation start date" }, new QueryArgument <NonNullGraphType <DateGraphType> > { Name = "FinishDate", Description = "Vacation finish date" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Status", Description = "Status of the vacation" }, new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Comment", Description = "Comment of the vacation" } ), resolve: context => { int userId = context.GetArgument <int>("UserId"); DateTime startDate = context.GetArgument <DateTime>("StartDate"); DateTime finishDate = context.GetArgument <DateTime>("FinishDate"); string status = context.GetArgument <string>("Status"); string comment = context.GetArgument <string>("Comment"); return(dataBaseRepository.AddRequest(userId, startDate, finishDate, status, comment)); }, description: "Returns user requests." ).AuthorizeWith("Authenticated"); Field <ListGraphType <VacationRequestType> >( "removeVacationRequest", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "Id", Description = "Vacation request id" } ), resolve: context => { int id = context.GetArgument <int>("Id"); return(dataBaseRepository.RemoveRequest(id)); }, description: "Returns user requests." ).AuthorizeWith("Authenticated"); Field <BooleanGraphType>( "sendResetPasswordLink", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Email", Description = "User email" } ), resolve: context => { string email = context.GetArgument <string>("Email"); User user = dataBaseRepository.Get(email); if (user == null) { return(false); } string token = identityService.GenerateResetPasswordAccessToken(email); try { emailService.SendRestorePasswordEmail(email, token); } catch { return(false); } return(true); } ); Field <StringGraphType>( "resetPassword", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "Password", Description = "New password to acccount." } ), resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); string token = httpContext.HttpContext.Request.Headers.First(header => header.Key == "Authorization").Value.ToString().Replace("Bearer ", ""); Token jwt = dataBaseRepository.GetJWT(token); string password = context.GetArgument <string>("Password"); string salt = Guid.NewGuid().ToString(); User user = dataBaseRepository.Get(email); if (user.Password == Hashing.GetHashString(password + user.Salt)) { return("The new password cannot match the current password."); } if (jwt == null) { return(""); } dataBaseRepository.RemoveJWT(token); user.Password = Hashing.GetHashString(password + user.Salt); dataBaseRepository.EditUser(user); return("Success"); } ).AuthorizeWith("canResetPassword"); Field <BooleanGraphType>( "checkAccessToResetPasswordPage", resolve: context => { string token = httpContext.HttpContext.Request.Headers.First(header => header.Key == "Authorization").Value.ToString().Replace("Bearer ", ""); Token jwt = dataBaseRepository.GetJWT(token); if (jwt == null) { return(false); } return(true); } ).AuthorizeWith("canResetPassword"); Field <TimerHistoryType>( "addTimerStartValue", resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); DateTime startTime = DateTime.UtcNow; return(dataBaseRepository.AddTimerStartValue(startTime, user.Id)); }, description: "Add start time" ).AuthorizeWith("Authenticated"); Field <TimerHistoryType>( "addTimerValue", arguments: new QueryArguments( new QueryArgument <DateTimeGraphType> { Name = "StartTime", Description = "Timer started" }, new QueryArgument <DateTimeGraphType> { Name = "FinishTime", Description = "Timer finished" } ), resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); Nullable <DateTime> startTime = context.GetArgument <Nullable <DateTime> >("StartTime", defaultValue: null); Nullable <DateTime> finishTime = context.GetArgument <Nullable <DateTime> >("FinishTime", defaultValue: null); return(dataBaseRepository.AddTimerValue(startTime, finishTime, user.Id)); }, description: "Add start time" ).AuthorizeWith("Authenticated"); Field <TimerHistoryType>( "editTimerFinishValue", arguments: new QueryArguments( new QueryArgument <DateTimeGraphType> { Name = "StartTime", Description = "Timer started" }, new QueryArgument <DateTimeGraphType> { Name = "FinishTime", Description = "Timer finished" }, new QueryArgument <IntGraphType> { Name = "id", Description = "Edit Timer finished" } ), resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); Nullable <DateTime> startTime = context.GetArgument <Nullable <DateTime> >("StartTime", defaultValue: null); Nullable <DateTime> finishTime = context.GetArgument <Nullable <DateTime> >("FinishTime", defaultValue: null); finishTime = (finishTime == null) ? DateTime.UtcNow : finishTime; Nullable <int> id = context.GetArgument <Nullable <int> >("id", defaultValue: null); return(dataBaseRepository.EditTimerValue(startTime, finishTime, user.Id, id)); }, description: "Update value: added finish time" ).AuthorizeWith("Authenticated"); Field <TimerHistoryType>( "deleteTimerFinishValue", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "id", Description = "Edit Timer finished" } ), resolve: context => { int id = context.GetArgument <int>("id"); return(dataBaseRepository.DeteleTimerValue(id)); }, description: "Update value: added finish time" ); }
public Querys(IHttpContextAccessor httpContext, DataBaseRepository dataBaseRepository) { Name = "Query"; Field <UserType>( "GetCurrentUser", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); user.ComputedProps = new ComputedProps(); user.ComputedProps.AddPermission(dataBaseRepository.GetPermission(user.Id)); user.ComputedProps.Teams = dataBaseRepository.GetUserTeams(user.Id); return(user); } ).AuthorizeWith("Authenticated"); Field <ListGraphType <TeamType> >( "GetTeams", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); return(dataBaseRepository.GetListOfAvailableTeams(user.Id)); }, description: "Get list of available teams." ).AuthorizeWith("Manager"); Field <ListGraphType <TeamType> >( "GetUserTeams", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); return(dataBaseRepository.GetUserTeams(user.Id)); } ).AuthorizeWith("Authenticated"); Field <ListGraphType <UserType> >( "GetTeamUsers", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "TeamId", Description = "Team id." } ), resolve: context => { int teamId = context.GetArgument <int>("TeamId"); return(dataBaseRepository.GetTeamUsers(teamId)); } ).AuthorizeWith("Authenticated"); Field <ListGraphType <StringGraphType> >( "GetAllPermissions", arguments: null, resolve: context => { return(dataBaseRepository.GetAllPermissions()); } ).AuthorizeWith("Manager"); Field <ListGraphType <VacationRequestType> >( "GetCurrentUserRequests", arguments: null, resolve: context => { string email = httpContext.HttpContext.User.Claims.First(claim => claim.Type == "Email").Value.ToString(); User user = dataBaseRepository.Get(email); int id = user.Id; return(dataBaseRepository.GetUserRequests(user.Id)); } ).AuthorizeWith("Authenticated"); }
public LedenAdministratie(DataBaseRepository dataBaseRepository) { _dataBaseRepository = dataBaseRepository; ValidationMessage = new MessageService(); }