public string GetAllUtilities() { var result = ""; using (diplomaDBContext = new DiplomaDBContext()) { var utilities = diplomaDBContext.Utility.ToArray(); var utilityLocation = new UtilityLocation[utilities.Length]; for (int i = 0; i < utilityLocation.Length; i++) { var location = new Diploma_WebControllerAPI.ViewModels.Location { Latitude = diplomaDBContext.Location.Single(l => l.Id == utilities[i].LocationId).Latitude, Longitude = diplomaDBContext.Location.Single(l => l.Id == utilities[i].LocationId).Longitude }; utilityLocation[i] = new UtilityLocation { Id = utilities[i].Id, Name = utilities[i].Name, Ready = utilities[i].Ready, Regions = diplomaDBContext.Region.Where(r => r.UtilityId == utilities[i].Id).Select(r => r.Name).ToArray(), Location = location }; } result = JsonSerializer.Serialize(utilityLocation, JsonOptions); } Response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:3000"); return(result); }
public int SaveRegion(RegionSaveModel regionSaveModel) { try { using (var dbContext = new DiplomaDBContext()) { var region = new Region { Id = dbContext.Region.Count() + 1, Name = regionSaveModel.name, Population = regionSaveModel.population.HasValue ? regionSaveModel.population.Value : 0, Map = JsonSerializer.Serialize <LatLng[]>(regionSaveModel.path), UtilityId = regionSaveModel.utility, RecycleFactoryId = regionSaveModel.sortStation, CityId = regionSaveModel.city }; dbContext.Region.Add(region); dbContext.SaveChanges(); return(1); } } catch { return(0); } }
public string GetAllFactories() { var result = ""; using (diplomaDBContext = new DiplomaDBContext()) { var factories = diplomaDBContext.RecycleFactory.ToArray(); var factoryLocation = new FactoryLocation[factories.Length]; for (int i = 0; i < factoryLocation.Length; i++) { var location = new Diploma_WebControllerAPI.ViewModels.Location { Latitude = diplomaDBContext.Location.Single(l => l.Id == factories[i].LocationId).Latitude, Longitude = diplomaDBContext.Location.Single(l => l.Id == factories[i].LocationId).Longitude }; var region = diplomaDBContext.Region.FirstOrDefault(r => r.RecycleFactoryId == factories[i].Id); factoryLocation[i] = new FactoryLocation { Id = factories[i].Id, Name = factories[i].Name, Ready = factories[i].Ready, Region = region == null ? "" : region.Name, Location = location }; } result = JsonSerializer.Serialize(factoryLocation, JsonOptions); } Response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:3000"); return(result); }
public bool Generate() { var cities = new List <City>(); cities.Add(new City { Id = 1, Name = "Київ", Population = 2884974 }); cities.Add(new City { Id = 2, Name = "Львів", Population = 721301 }); cities.Add(new City { Id = 3, Name = "Харків", Population = 1419765 }); cities.Add(new City { Id = 4, Name = "Одеса", Population = 993120 }); using (var dimplomaDbContext = new DiplomaDBContext()) { if (dimplomaDbContext.City.Count() == cities.Count) { return(true); } dimplomaDbContext.City.AddRange(cities); var result = dimplomaDbContext.SaveChanges(); return(result > 0); } }
public string RegionDashboard(int id) { var result = ""; using (diplomaDBContext = new DiplomaDBContext()) { var dailyTripList = diplomaDBContext.Trip.Where(t => t.Date.Date == DateTime.Today && !t.InProgress && t.TripContainers.Any() && t.TripContainers.First().Container.Region.Id == id).ToList(); var dailyStatistics = new RegionDailyStatistics { Date = DateTime.Today, AvgTime = (long?)dailyTripList.Average(t => t.Time), AvgPetrolAmount = (int?)dailyTripList.Average(t => t.PetrolAmount.Value), PetrolAmount = dailyTripList.Sum(t => t.PetrolAmount).HasValue ? dailyTripList.Sum(t => t.PetrolAmount).Value : 0, AvgDynamicChangesCount = (int?)dailyTripList.Average(t => t.DynamicChangesCount.Value), DynamicChangesCount = dailyTripList.Sum(t => t.DynamicChangesCount).HasValue ? dailyTripList.Sum(t => t.DynamicChangesCount).Value : 0, AvgContainersCount = (int?)dailyTripList.Average(t => t.TripContainers.Count()), CollectedContainersCount = dailyTripList.Sum(t => t.TripContainers.Count()), ContainersCount = diplomaDBContext.Container.Count(), UtilityId = dailyTripList.First().UtilityId, RegionId = dailyTripList.First().TripContainers.First().Container.RegionId }; result = JsonSerializer.Serialize(dailyStatistics, JsonOptions); } return(result); }
public ProjectTask Get(Guid projectTaskId) { using (var context = new DiplomaDBContext()) { return(context.ListOfProjectTasks.SingleOrDefault(x => x.Id == projectTaskId)); } }
public string BuildTripByRegion(int regionId) { using (diplomaDBContext = new DiplomaDBContext()) { //var containers = diplomaDBContext.Container.Where(c => c.RegionId == regionId).Where(c => c.Full).ToArray(); var containers = diplomaDBContext.Container.Where(c => c.RegionId == regionId).ToArray(); GA_TSP tsp = new GA_TSP(containers); tsp.Initialization(); var indexes = tsp.TSPCompute(); var tripContainers = new List <Container>(); string containerIndexes = "[ "; for (int i = 0; i < indexes.Length; i++) { tripContainers.Add(containers[indexes[i]]); containerIndexes += indexes[i].ToString() + ", "; } containerIndexes += "]"; return(containerIndexes); } }
public Project GetById(Guid id) { using (var context = new DiplomaDBContext()) { return(context.ListOfProjects.Where(x => x.Id == id).Include(x => x.Promo).FirstOrDefault()); } }
public void Delete(Guid id, string userEmail) { using (var context = new DiplomaDBContext()) { var proj = context.ListOfProjects.Where(x => x.Id == id).FirstOrDefault(); var taskList = context.ListOfProjects.Where(x => x.Id == id).FirstOrDefault().ListOfProjectTasks; var user = context.ListOfUsers.Where(x => x.Email == userEmail).FirstOrDefault(); if (user != null) { proj.Promo = null; if (taskList != null) { context.ListOfProjectTasks.RemoveRange(taskList); } proj.ListOfProjectTasks.RemoveAll(x => x.Id != null); context.ListOfProjects.Attach(proj); user.ListOfProjects.Remove(proj); context.ListOfProjects.Remove(proj); context.SaveChanges(); } } }
public IEnumerable <Project> GetAll() { using (var context = new DiplomaDBContext()) { return(context.ListOfProjects); } }
public string CountryDashboard() { var result = ""; using (diplomaDBContext = new DiplomaDBContext()) { var dailyTripList = diplomaDBContext.Trip.Where(t => t.Date.Date == DateTime.Today && !t.InProgress).ToList(); var dailyStatistics = new CountryDailyStatistics { Date = DateTime.Today, CitiesCount = diplomaDBContext.City.Count(), AvgTime = (long?)dailyTripList.Average(t => t.Time), AvgPetrolAmount = (int?)dailyTripList.Average(t => t.PetrolAmount.Value), PetrolAmount = dailyTripList.Sum(t => t.PetrolAmount).HasValue ? dailyTripList.Sum(t => t.PetrolAmount).Value : 0, AvgDynamicChangesCount = (int?)dailyTripList.Average(t => t.DynamicChangesCount.Value), DynamicChangesCount = dailyTripList.Sum(t => t.DynamicChangesCount).HasValue ? dailyTripList.Sum(t => t.DynamicChangesCount).Value : 0, AvgContainersCount = (int?)dailyTripList.Average(t => t.TripContainers.Count()), CollectedContainersCount = dailyTripList.Sum(t => t.TripContainers.Count()), ContainersCount = diplomaDBContext.Container.Count(), UtilitiesCount = diplomaDBContext.Utility.Count(), RegionsCount = diplomaDBContext.Region.Count(), FactoriesCount = diplomaDBContext.RecycleFactory.Count() }; result = JsonSerializer.Serialize(dailyStatistics, JsonOptions); } return(result); }
public string GetAllContainers() { var result = ""; using (diplomaDBContext = new DiplomaDBContext()) { var containers = diplomaDBContext.Container.ToArray(); var containersLocation = new ContainerLocation[containers.Length]; for (int i = 0; i < containersLocation.Length; i++) { var location = new Diploma_WebControllerAPI.ViewModels.Location { Latitude = diplomaDBContext.Location.Single(l => l.Id == containers[i].LocationId).Latitude, Longitude = diplomaDBContext.Location.Single(l => l.Id == containers[i].LocationId).Longitude }; containersLocation[i] = new ContainerLocation { Id = containers[i].Id, Full = containers[i].Full, LastGather = containers[i].LastGather, LastUpdate = containers[i].LastUpdate, Region = diplomaDBContext.Region.Single(l => l.Id == containers[i].RegionId).Name, Location = location }; } result = JsonSerializer.Serialize(containersLocation, JsonOptions); } Response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:3000"); return(result); }
public string GetAllRegions() { var result = ""; using (diplomaDBContext = new DiplomaDBContext()) { var regions = diplomaDBContext.Region.Where(r => r.Map != "").ToArray(); var regionLocations = new RegionLocation[regions.Length]; for (int i = 0; i < regionLocations.Length; i++) { regionLocations[i] = new RegionLocation { Id = regions[i].Id, Name = regions[i].Name, Map = regions[i].Map }; } result = JsonSerializer.Serialize(regionLocations, JsonOptions); } Response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:3000"); return(result); }
public void Add(User user) { using (DiplomaDBContext db = new DiplomaDBContext()) { user.Password = HashService.HashPassword(user.Password); db.ListOfUsers.Add(user); db.SaveChanges(); } }
public int SaveBuilding(BuildingSaveModel buildingSaveModel) { try { using (var dbContext = new DiplomaDBContext()) { var locationId = dbContext.Location.Count() + 1; var location = new Location { Id = locationId, Latitude = buildingSaveModel.location.lat, Longitude = buildingSaveModel.location.lng }; dbContext.Location.Add(location); if (buildingSaveModel.type == 0) { var utilityId = dbContext.Utility.Count() + 1; var utility = new Utility { Id = utilityId, Name = buildingSaveModel.name, LocationId = locationId, Ready = buildingSaveModel.ready, UtilityCompanyId = buildingSaveModel.utilityCompany.Value, UtilityOptionsId = 1 }; dbContext.Utility.Add(utility); } else { var factoryId = dbContext.RecycleFactory.Count() + 1; var factory = new RecycleFactory { Id = factoryId, Name = buildingSaveModel.name, LocationId = locationId, Ready = buildingSaveModel.ready }; dbContext.RecycleFactory.Add(factory); } dbContext.SaveChanges(); return(1); } } catch { return(0); } }
public void ChangePassword(string userEmail, string newPassword) { using (DiplomaDBContext db = new DiplomaDBContext()) { User user = db.ListOfUsers.Where(x => x.Email == userEmail).FirstOrDefault(); user.Password = HashService.HashPassword(newPassword); db.SaveChanges(); } }
public User GetByKey(string userEmail) { User user = new User(); using (DiplomaDBContext db = new DiplomaDBContext()) { user = db.ListOfUsers.Where(x => x.Email == userEmail).FirstOrDefault(); return(user); } }
public IEnumerable <Project> GetAllByUserId(string userEmail) { using (var context = new DiplomaDBContext()) { var singleOrDefault = context.ListOfUsers.SingleOrDefault(x => x.Email == userEmail); if (singleOrDefault != null) { return(singleOrDefault.ListOfProjects); } return(null); } }
public void Create(Guid projectId, ProjectTask newProjectTask) { using (var context = new DiplomaDBContext()) { var project = context.ListOfProjects.SingleOrDefault(x => x.Id == projectId); if (project != null) { project.ListOfProjectTasks.Add(newProjectTask); } context.SaveChanges(); } }
public IEnumerable <ProjectTask> GetAllByProject(Guid projectId) { using (var context = new DiplomaDBContext()) { var project = context.ListOfProjects.SingleOrDefault(x => x.Id == projectId); if (project != null) { return(project.ListOfProjectTasks.OrderBy(x => x.DeadLine)); } return(null); } }
public IEnumerable <ProjectTask> GetFailedByProject(Guid projectId) { using (var context = new DiplomaDBContext()) { var project = context.ListOfProjects.SingleOrDefault(x => x.Id == projectId); if (project != null) { return(project.ListOfProjectTasks.Where(x => x.EndDate == (DateTime)SqlDateTime.MinValue).OrderBy(x => x.DeadLine)); } return(null); } }
public void ActivateAccount(string userEmail, string hash) { using (DiplomaDBContext db = new DiplomaDBContext()) { User user = db.ListOfUsers.Where(x => x.Email == userEmail).FirstOrDefault(); if (HashService.GenerateUserHash(user) == hash) { user.EmailActivated = true; db.SaveChanges(); } } }
public string Regions(int id) { var result = ""; using (diplomaDBContext = new DiplomaDBContext()) { var regions = diplomaDBContext.Region.Where(r => r.CityId == id).Select(r => new RegionViewModel(r)).ToList(); result = JsonSerializer.Serialize(regions, JsonOptions); } return(result); }
public string Cities() { var result = ""; using (diplomaDBContext = new DiplomaDBContext()) { var cities = diplomaDBContext.City.Select(c => new CityViewModel(c)).ToList(); result = JsonSerializer.Serialize(cities, JsonOptions); } return(result); }
public UndoneTaskPerProject GetUndoneTasks(Guid id) { using (var context = new DiplomaDBContext()) { var project = context.ListOfProjects.SingleOrDefault(x => x.Id == id); var taskService = new ProjectTaskService(); var listOfUndoneTasks = taskService.GetAllByProject(id).Where(x => x.EndDate == (DateTime)SqlDateTime.MinValue).OrderBy(x => x.DeadLine).ToList(); return(new UndoneTaskPerProject() { Project = project, UndoneProjectTasks = listOfUndoneTasks }); } }
public void Delete(Guid projectId, Guid projectTaskId) { using (var context = new DiplomaDBContext()) { var project = context.ListOfProjects.SingleOrDefault(x => x.Id == projectId); if (project != null) { var projectTask = project.ListOfProjectTasks.SingleOrDefault(x => x.Id == projectTaskId); project.ListOfProjectTasks.Remove(projectTask); context.ListOfProjectTasks.Remove(projectTask); } context.SaveChanges(); } }
public IEnumerable <UndoneTaskPerProject> GetAllUndoneTasksByUser(string userEmail) { using (var context = new DiplomaDBContext()) { var user = context.ListOfUsers.SingleOrDefault(x => x.Email == userEmail); if (user != null) { foreach (var project in user.ListOfProjects) { yield return(GetUndoneTasks(project.Id)); } } } }
public static void BuildPasswordRecoveryEmailTemplate(string userEmail) { using (DiplomaDBContext db = new DiplomaDBContext()) { string body = System.IO.File.ReadAllText(HostingEnvironment.MapPath("~/EmailTemplates/") + "Password" + ".cshtml"); var user = db.ListOfUsers.Where(x => x.Email == userEmail).FirstOrDefault(); if (user != null) { var url = "http://*****:*****@ViewBag.ConfirmationLink", url); body = body.ToString(); BuildEmailTemlplate("Przypomnienie hasła", body, user.Email); } } }
public void Update(Guid id, Project updatedProject, string userEmail) { using (var context = new DiplomaDBContext()) { var user = context.ListOfUsers.SingleOrDefault(x => x.Email == userEmail); if (user != null) { var project = user.ListOfProjects.SingleOrDefault(x => x.Id == id); if (project != null) { project = updatedProject; } } context.SaveChangesAsync(); } }
public int[] GetStatisticsDoneUndoneFailedTasks(Guid projectId) { using (var context = new DiplomaDBContext()) { var taskService = new ProjectTaskService(); var doneTasksCount = taskService .GetAllByProject(projectId) .Count(x => x.EndDate != (DateTime)SqlDateTime.MinValue); var undoneTasksCount = taskService .GetAllByProject(projectId) .Count(x => x.EndDate == (DateTime)SqlDateTime.MinValue); var failedTasksCount = taskService .GetAllByProject(projectId) .Count(x => x.DeadLine < DateTime.Today && x.EndDate == (DateTime)SqlDateTime.MinValue); return(new[] { doneTasksCount, undoneTasksCount, failedTasksCount }); } }