public async Task <ActionResult <SearchResultViewModel <ShiftViewModel> > > GetShiftsAsync(ShiftFilter filter) { if (filter == null) { return(BadRequest("No filter received")); } try { TaskListResult <Shift> result = await shiftService.GetShiftsAsync(filter); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data == null || result.Data.Count == 0) { return(Ok(new SearchResultViewModel <ShiftViewModel>(0, new List <ShiftViewModel>()))); } List <ShiftViewModel> shiftVmList = result.Data.Select(ShiftViewModel.CreateVm) .ToList(); return(Ok(new SearchResultViewModel <ShiftViewModel>(filter.TotalItemCount, shiftVmList))); } catch (Exception ex) { string message = GetType() .Name + "Error in " + nameof(GetShiftAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <List <ManagerViewModel> > > GetProjectsManagedByAsync(Guid userId) { if (userId == Guid.Empty) { return(BadRequest("No valid id received")); } try { TaskListResult <Manager> result = await personService.GetProjectsManagedByAsync(userId); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data == null || result.Data.Count == 0) { return(Ok(new List <ManagerViewModel>())); } List <ManagerViewModel> managerVmList = result.Data.Select(ManagerViewModel.CreateVm).ToList(); return(Ok(managerVmList)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetProjectsManagedByAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
private void button9_Click(object sender, EventArgs e) { TaskListResult result = new TaskListResult(); TaskListTest param = new TaskListTest(); string server = "http://localhost:15988/api/TeamTask/TestLink"; param.type = "test"; param.val = "123654"; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("type", param.type); dic.Add("val", param.val); try { HttpWebResponse response = CreatePostHttpResponse(server, dic, null, null, Encoding.UTF8, null); System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()); string responseContent = sr.ReadToEnd(); sr.Close(); TaskListResult rtn = Deserialize <TaskListResult>(responseContent); MessageBox.Show(rtn.val); } catch (Exception ex) { return; } }
public async Task <ActionResult <List <CategoryViewModel> > > GetAllCategoriesAsync() { try { TaskListResult <Category> result = await taskService.GetAllCategoriesAsync(); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data.Count == 0) { return(Ok(new List <CategoryViewModel>())); } List <CategoryViewModel> categoryViewmodels = result.Data .Select(CategoryViewModel.CreateVm) .ToList(); return(Ok(categoryViewmodels)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetAllCategoriesAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <List <TaskViewModel> > > SearchTasksAsync(string name, int offset = 0, int pageSize = 20) { TaskFilter filter = new TaskFilter(offset, pageSize) { Name = name }; try { TaskListResult <Task> result = await taskService.SearchTasksAsync(filter); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data == null) { return(Ok(new List <TaskViewModel>())); } List <TaskViewModel> taskVmList = result.Data.Select(TaskViewModel.CreateVm).ToList(); return(Ok(new SearchResultViewModel <TaskViewModel>(filter.TotalItemCount, taskVmList))); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(SearchTasksAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <List <AvailabilityViewModel> > > GetScheduledAvailabilities(Guid participationId) { if (participationId == Guid.Empty) { return(BadRequest("No vaild participationId")); } try { TaskListResult <Availability> taskListResult = await availabilityService.GetScheduledAvailabilities(participationId); if (!taskListResult.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = taskListResult.Message })); } if (taskListResult.Data.Count == 0) { return(Ok(new List <AvailabilityViewModel>())); } List <AvailabilityViewModel> list = taskListResult.Data.Select(AvailabilityViewModel.CreateVm).ToList(); return(Ok(list)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetScheduledAvailabilities); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <List <ShiftViewModel> > > GetShiftsAsync(Guid projectId, DateTime date) { if (projectId == Guid.Empty) { return(BadRequest("No valid projectId")); } try { TaskListResult <Shift> result = await shiftService.GetShiftsAsync(projectId, date); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data == null || result.Data.Count == 0) { return(Ok(new List <ShiftViewModel>())); } List <ShiftViewModel> shiftVmList = result.Data.Select(ShiftViewModel.CreateVm) .ToList(); return(Ok(shiftVmList)); } catch (Exception ex) { string message = GetType() .Name + "Error in " + nameof(GetShiftAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <bool> > SendEmailAsync(Guid projectId, MessageViewModel emailMessage) { if (projectId == Guid.Empty) { return(BadRequest("No valid id.")); } if (emailMessage?.Body == null || emailMessage.Subject == null) { return(BadRequest("No valid message.")); } try { TaskListResult <Participation> participations = await participationService.GetParticipationsAsync(projectId); if (!participations.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = participations.Message })); } foreach (Participation participation in participations.Data) { TaskResult <User> user = await personService.GetUserAsync(participation.PersonId); TaskResult <Person> person = await personService.GetPersonAsync(participation.PersonId); if (!user.Succeeded || !person.Succeeded || person.Data.PushDisabled) { continue; } string email = user.Data.Identities.FirstOrDefault()?.IssuerAssignedId; if (email == null) { continue; } emailMessage.Body = emailMessage.Body.Replace("\n", "<br>"); participationService.SendEmail(email, emailMessage.Subject, emailMessage.Body, true, null, null); } return(Ok()); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(SendEmailAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <ParticipationViewModel> > RemoveParticipationAsync(Guid id) { if (id == Guid.Empty) { return(BadRequest("No valid id.")); } try { TaskResult <Participation> participation = await participationService.GetParticipationAsync(id); if (!participation.Succeeded) { BadRequest("Invalid participation"); } string oid = IdentityHelper.GetOid(HttpContext.User.Identity as ClaimsIdentity); if (oid == null) { return(BadRequest("Invalid User")); } if (oid != participation.Data.PersonId.ToString()) { return(Unauthorized()); } //controleer of gebruiker niet ingeroosterd staat TaskListResult <Availability> availabilities = await availabilityService.GetActiveAvailabilities(id); if (availabilities.Data.Count > 0) { return(BadRequest("Je kan je niet uitschrijven voor dit project. Je bent nog ingepland.")); } //gebruiker mag participation verwijderen participation.Data.Active = false; TaskResult <Participation> result = await participationService.UpdateParticipationAsync(participation.Data); return(!result.Succeeded ? UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message }) : Ok(result)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(RemoveParticipationAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <List <ManagerViewModel> > > GetProjectManagersAsync(Guid projectId) { if (projectId == Guid.Empty) { return(BadRequest("No valid id received")); } try { TaskListResult <Manager> result = await personService.GetManagersAsync(projectId); //get users from b2c and add tot DTO foreach (Manager manager in result.Data) { User temp = (await personService.GetUserAsync(manager.PersonId)).Data; if (temp == null) { continue; } PersonViewModel vm = PersonViewModel.CreateVmFromUser(temp, Extensions.GetInstance(b2CExtentionApplicationId)); if (vm == null) { continue; } Person person = PersonViewModel.CreatePerson(vm); manager.Person = person; } if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data == null || result.Data.Count == 0) { return(Ok(new List <ManagerViewModel>())); } List <ManagerViewModel> managerVmList = result.Data.Select(ManagerViewModel.CreateVm).ToList(); return(Ok(managerVmList)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetProjectManagersAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <PersonViewModel> > GetPersonAsync(string email, string firstName, string lastName, string userRole, string city, int offset = 0, int pageSize = 20) { PersonFilter filter = new PersonFilter(offset, pageSize) { Email = email, FirstName = firstName, LastName = lastName, UserRole = userRole, City = city }; List <PersonViewModel> personViewModels = new List <PersonViewModel>(); try { TaskListResult <User> result = await personService.GetB2CMembersAsync(filter); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data == null) { return(Ok(new List <PersonViewModel>())); } foreach (User user in result.Data) { personViewModels.Add(PersonViewModel.CreateVmFromUser(user, Extensions.GetInstance(b2CExtentionApplicationId))); if (personViewModels.Count == pageSize) { break; } } return(Ok(new SearchResultViewModel <PersonViewModel>(filter.TotalItemCount, personViewModels))); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetPersonAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <List <ProjectViewModel> > > SearchProjectsAsync(string name, string city, DateTime?startDateFrom = null, DateTime?endDate = null, bool?closed = null, int offset = 0, int pageSize = 20) { ProjectFilter filter = new ProjectFilter(offset, pageSize) { Name = name, City = city, StartDate = startDateFrom, EndDate = endDate, Closed = closed }; try { TaskListResult <Project> result = await projectService.SearchProjectsAsync(filter); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data == null) { return(Ok(new List <ProjectViewModel>())); } List <ProjectViewModel> projectVmList = result.Data.Select(ProjectViewModel.CreateVm).ToList(); return(Ok(new SearchResultViewModel <ProjectViewModel>(filter.TotalItemCount, projectVmList))); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(SearchProjectsAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
/** * 获取任务列表 */ public static void getTaskList(Action <Error, UserTaskMongoModel> action) { HttpUtil.Http.Get(URLManager.taskListUrl()).OnSuccess(result => { if (result != null) { TaskListResult taskList = JsonMapper.ToObject <TaskListResult>(result); action(null, taskList.data); } else { action(new Error(500, null), null); } }).OnFail(result => { action(new Error(500, null), null); }).GoSync(); }
public async Task <ActionResult <List <PersonViewModel> > > GetParticipants(Guid projectId) { if (projectId == Guid.Empty) { return(BadRequest("No valid id")); } try { TaskListResult <Participation> participationResult = await participationService.GetParticipationsAsync(projectId); if (!participationResult.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = participationResult.Message })); } List <PersonViewModel> persons = new List <PersonViewModel>(); foreach (Participation participation in participationResult.Data) { TaskResult <User> userResult = await personService.GetUserAsync(participation.PersonId); if (userResult != null) { persons.Add(PersonViewModel.CreateVmFromUser(userResult.Data, Extensions.GetInstance(b2CExtentionApplicationId))); } } return(Ok(persons)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetParticipants); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public TaskListResult TestLink([FromBody] TaskListTest param) { //记时 LogHelper.Info("TestLink--开始"); Stopwatch timeWatcher = new Stopwatch(); long checkTime = 0; timeWatcher.Restart(); //开始计时 TaskListResult result = new TaskListResult(); result.val = "success"; if (param == null) { param = new TaskListTest(); this.Request.GetQueryNameValuePairs(); HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; //获取传统context HttpRequestBase request = context.Request; //定义传统request对象 param.type = request.Form["type"]; param.val = request.Form["val"]; LogHelper.Info("WebApi-TestLink param from forms"); } try { result.val = param.val; } catch (Exception ex) { LogHelper.Error(ex.Message); result.val = ex.Message; return(result); } timeWatcher.Stop();//结束计时 checkTime = timeWatcher.ElapsedMilliseconds; LogHelper.Info(string.Format("TestLink--结束,执行时间:{0} ", checkTime)); return(result); }
public async Task <ActionResult <List <TaskViewModel> > > GetAllProjectTasksAsync(Guid projectId) { if (projectId == Guid.Empty) { return(BadRequest("No valid id.")); } try { TaskListResult <ProjectTask> result = await taskService.GetAllProjectTasksAsync(projectId); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data.Count == 0) { return(Ok(new List <ProjectTaskViewModel>())); } List <TaskViewModel> taskViewModels = result.Data.Select(projectTask => TaskViewModel.CreateVm(projectTask.Task)).ToList(); return(Ok(taskViewModels)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetAllProjectTasksAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <List <ParticipationViewModel> > > GetUserParticipationAsync(Guid personId) { if (personId == Guid.Empty) { return(BadRequest("No valid id.")); } try { TaskListResult <Participation> result = await participationService.GetUserParticipationsAsync(personId); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data.Count == 0) { return(Ok(new List <ParticipationViewModel>())); } List <ParticipationViewModel> participationViewModels = result.Data .Select(ParticipationViewModel.CreateVm) .ToList(); return(Ok(participationViewModels)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetParticipationAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <AvailabilityDataViewModel> > GetAvailabilityData(Guid projectId) { if (projectId == Guid.Empty) { return(BadRequest("No valid projectId.")); } try { TaskListResult <ProjectTask> taskResult = await taskService.GetAllProjectTasksAsync(projectId); TaskListResult <Shift> shiftResult = await shiftService.GetShiftsWithAvailabilitiesAsync(projectId); if (!taskResult.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = taskResult.Message })); } if (!shiftResult.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = shiftResult.Message })); } List <Schedule> knownAvailabilities = new List <Schedule>(); foreach (IGrouping <DateTime, Shift> grouping in shiftResult.Data.GroupBy(s => s.Date)) { List <AvailabilityStatus> dateStatus = new List <AvailabilityStatus>(); foreach (Shift shift in grouping) { int numberOfAvailabilities = shift.Availabilities.Where(a => a.Type == AvailibilityType.Ok).Count(); int numberOfSchedule = shift.Availabilities.Count(a => a.Type == AvailibilityType.Scheduled); if (numberOfSchedule >= shift.ParticipantsRequired) { dateStatus.Add(AvailabilityStatus.Scheduled); } else if (numberOfAvailabilities >= shift.ParticipantsRequired) { dateStatus.Add(AvailabilityStatus.Complete); } else { dateStatus.Add(AvailabilityStatus.Incomplete); } } Schedule schedule = new Schedule(grouping.Key, AvailabilityStatus.Incomplete); if (dateStatus.All(a => a == AvailabilityStatus.Complete || a == AvailabilityStatus.Scheduled)) { schedule.Status = AvailabilityStatus.Complete; } if (dateStatus.All(a => a == AvailabilityStatus.Scheduled)) { schedule.Status = AvailabilityStatus.Scheduled; } knownAvailabilities.Add(schedule); } List <TaskViewModel> taskViewModels = taskResult.Data .Select(projectTask => TaskViewModel.CreateVm(projectTask.Task)).ToList(); AvailabilityDataViewModel vm = new AvailabilityDataViewModel { ProjectTasks = taskViewModels, KnownAvailabilities = knownAvailabilities }; return(Ok(vm)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetAvailabilityData); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <AvailabilityDataViewModel> > GetAvailabilityData(Guid projectId, Guid userId) { if (projectId == Guid.Empty) { return(BadRequest("No valid projectId.")); } if (userId == Guid.Empty) { return(BadRequest("No valid userId.")); } try { TaskListResult <ProjectTask> taskResult = await taskService.GetAllProjectTasksAsync(projectId); TaskListResult <Shift> shiftResult = await shiftService.GetShiftsWithAvailabilitiesAsync(projectId, userId); TaskResult <Person> person = await personService.GetPersonAsync(userId); if (!taskResult.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = taskResult.Message })); } if (!shiftResult.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = shiftResult.Message })); } if (!person.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = person.Message })); } List <Schedule> knownAvailabilities = new List <Schedule>(); foreach (IGrouping <DateTime, Shift> grouping in shiftResult.Data.GroupBy(s => s.Date)) { int numberOfShifts = grouping.Count(); int numberOfAvailabilities = 0; bool scheduled = false; bool anyAvailable = false; foreach (Shift shift in grouping) { if (shift.Availabilities.Count <= 0) { continue; } numberOfAvailabilities++; shift.Availabilities.ForEach(a => { if (a.Type == AvailibilityType.Scheduled) { scheduled = true; } else if (a.Type == AvailibilityType.Ok) { anyAvailable = true; } }); } if (scheduled) { knownAvailabilities.Add(new Schedule(grouping.Key, AvailabilityStatus.Scheduled)); } else if (anyAvailable) { knownAvailabilities.Add(new Schedule(grouping.Key, AvailabilityStatus.Complete)); } else if (numberOfAvailabilities > 0 && !anyAvailable) { knownAvailabilities.Add(new Schedule(grouping.Key, AvailabilityStatus.Unavailable)); } else { knownAvailabilities.Add(new Schedule(grouping.Key, AvailabilityStatus.Incomplete)); } } List <TaskViewModel> taskViewModels = taskResult.Data .Where(t => t.Task.Requirements .All(r => person.Data.Certificates .Where(c => c.DateExpired == null || c.DateExpired > DateTime.UtcNow) .Select(c => c.CertificateTypeId) .Contains(r.CertificateTypeId))) .Select(projectTask => TaskViewModel .CreateVm(projectTask.Task)) .ToList(); AvailabilityDataViewModel vm = new AvailabilityDataViewModel { ProjectTasks = taskViewModels, KnownAvailabilities = knownAvailabilities }; return(Ok(vm)); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(GetAvailabilityData); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <List <ShiftViewModel> > > ExportDataAsync(Guid projectId) { if (projectId == Guid.Empty) { return(BadRequest("No valid id.")); } try { TaskListResult <Shift> result = await shiftService.ExportDataAsync(projectId); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } if (result.Data == null || result.Data.Count == 0) { return(Ok(new List <ShiftViewModel>())); } List <ShiftViewModel> shiftVmList = new List <ShiftViewModel>(); List <PersonViewModel> personViewModels = new List <PersonViewModel>(); foreach (Shift shift in result.Data) { ShiftViewModel shiftVm = ShiftViewModel.CreateVm(shift); shiftVm.Availabilities = new List <AvailabilityViewModel>(); foreach (Availability availability in shift.Availabilities) { PersonViewModel pvm; Guid id = availability.Participation.PersonId; if (personViewModels.FirstOrDefault(pvms => pvms.Id == id) == null) { TaskResult <User> person = await personService.GetUserAsync(id); pvm = PersonViewModel.CreateVmFromUser(person.Data, Extensions.GetInstance(b2CExtentionApplicationId)); personViewModels.Add(pvm); } else { pvm = personViewModels.FirstOrDefault(pvm => pvm.Id == id); } AvailabilityViewModel avm = AvailabilityViewModel.CreateVm(availability); avm.Participation.Person = pvm; shiftVm.Availabilities.Add(avm); } shiftVmList.Add(shiftVm); } return(Ok(shiftVmList)); } catch (Exception ex) { string message = GetType() .Name + "Error in " + nameof(GetShiftAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <List <ShiftViewModel> > > SaveShiftsAsync(List <ShiftViewModel> shiftViewModels) { if (shiftViewModels == null || shiftViewModels.Count == 0) { return(BadRequest("No valid shifts received")); } try { //filter duplicate dates shiftViewModels = shiftViewModels.GroupBy(s => s.Date.Date) .Select(g => g.OrderByDescending(x => x.Date.Date).First()).ToList(); List <Shift> shifts = shiftViewModels.Select(ShiftViewModel.CreateShift) .ToList(); string oid = IdentityHelper.GetOid(HttpContext.User.Identity as ClaimsIdentity); if (shifts[0] != null) { //get project and get task from db Project project = (await projectService.GetProjectDetailsAsync(shifts[0] .ProjectId)).Data; Task task = null; if (shifts[0] .TaskId != null) { task = (await taskService.GetTaskAsync((Guid)shifts[0] .TaskId)).Data; } foreach (Shift shift in shifts) { if (shift.Id != Guid.Empty || shift.TaskId == null || shift.ProjectId == Guid.Empty) { shifts.Remove(shift); } // check if projectId and taskId differs from above? getproject/task => add project and task to shift if (project != null && project.Id != shift.ProjectId) { project = (await projectService.GetProjectDetailsAsync(shift.ProjectId)).Data; } if (task != null && shift.TaskId != null && task.Id != shift.TaskId) { task = (await taskService.GetTaskAsync((Guid)shift.TaskId)).Data; } if (project == null || task == null) { shifts.Remove(shift); } shift.Project = project; shift.Task = task; shift.LastEditBy = oid; } } if (shifts.Count != shiftViewModels.Count) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = "Could not covert al viewmodels to shifts" })); } TaskListResult <Shift> result = await shiftService.CreateShiftsAsync(shifts); if (!result.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = result.Message })); } List <ShiftViewModel> createdVm = result.Data.Select(ShiftViewModel.CreateVm) .ToList(); return(Ok(createdVm)); } catch (Exception ex) { string message = GetType() .Name + "Error in " + nameof(SaveShiftsAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <ScheduleDataViewModel> > GetScheduleAsync(Guid id) { if (id == Guid.Empty) { return(BadRequest()); } try { TaskResult <Shift> shiftResult = await shiftService.GetShiftWithAvailabilitiesAsync(id); if (!shiftResult.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = shiftResult.Message })); } if (shiftResult.Data == null) { return(NotFound()); } List <ScheduleViewModel> schedules = new List <ScheduleViewModel>(); //get a list with all days this week var culture = System.Threading.Thread.CurrentThread.CurrentCulture; int numberOfDaysBetweenNowAndStart = shiftResult.Data.Date.DayOfWeek - culture.DateTimeFormat.FirstDayOfWeek; if (numberOfDaysBetweenNowAndStart < 0) { numberOfDaysBetweenNowAndStart += 7; } DateTime firstDateThisWeek = shiftResult.Data.Date.Subtract(TimeSpan.FromDays(numberOfDaysBetweenNowAndStart)); List <DateTime> allDaysThisWeek = new List <DateTime>(); for (int i = 0; i < 7; i++) { allDaysThisWeek.Add(firstDateThisWeek.AddDays(i)); } foreach (Availability availability in shiftResult.Data.Availabilities .Where(a => a.Type == AvailibilityType.Ok || a.Type == AvailibilityType.Scheduled) ) //filter for people that are registerd to be able to work { //list all availabilities in this project of this person TaskListResult <Availability> availabilities = await availabilityService.FindAvailabilitiesAsync( availability.Participation.ProjectId, availability.Participation.PersonId); //lookup person information in B2C TaskResult <User> person = await personService.GetUserAsync(availability.Participation.PersonId); //see if person is scheduled this day and this shift if (availabilities.Data == null || availabilities.Data.Count <= 0) { continue; } int numberOfTimeScheduledThisDay = availabilities.Data .Where(a => a.Shift.Date == shiftResult.Data.Date) .Count(a => a.Type == AvailibilityType.Scheduled); bool scheduledThisShift = availabilities.Data.FirstOrDefault(a => a.ShiftId == id && a.Type == AvailibilityType.Scheduled) != null; //calculate the number of hours person is scheduled this week double numberOfHoursScheduleThisWeek = availabilities.Data .Where(a => a.Type == AvailibilityType.Scheduled && allDaysThisWeek.Contains(a.Shift.Date)) .Sum(availability1 => availability1.Shift.EndTime.Subtract(availability1.Shift.StartTime).TotalHours); //add scheduleViewmodel to list schedules.Add(new ScheduleViewModel { Person = PersonViewModel.CreateVmFromUser(person.Data, Extensions.GetInstance(b2CExtentionApplicationId)), NumberOfTimesScheduledThisProject = availabilities.Data.Count(a => a.Type == AvailibilityType.Scheduled), ScheduledThisDay = numberOfTimeScheduledThisDay > 0, ScheduledThisShift = scheduledThisShift, AvailabilityId = availability.Id, Preference = availability.Preference, Availabilities = availabilities.Data .Where(a => a.Shift.Date == shiftResult.Data.Date) .Select(AvailabilityViewModel.CreateVm) .ToList(), HoursScheduledThisWeek = numberOfHoursScheduleThisWeek, Employability = availability.Participation.MaxWorkingHoursPerWeek }); } ScheduleDataViewModel vm = new ScheduleDataViewModel { Schedules = schedules, Shift = ShiftViewModel.CreateVm(shiftResult.Data) }; return(Ok(vm)); } catch (Exception ex) { string message = GetType() .Name + "Error in " + nameof(GetScheduleAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }
public async Task <ActionResult <bool> > SendSchedule(Guid projectId) { if (projectId == Guid.Empty) { return(BadRequest("No valid id.")); } try { TaskListResult <Participation> participations = await participationService.GetParticipationsWithAvailabilitiesAsync(projectId); if (!participations.Succeeded) { return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = participations.Message })); } CultureInfo culture = new CultureInfo("en-US"); foreach (Participation participation in participations.Data.Where(participation => participation.Availabilities.Count > 0)) { TaskResult <User> user = await personService.GetUserAsync(participation.PersonId); TaskResult <Person> person = await personService.GetPersonAsync(participation.PersonId); if (!user.Succeeded || !person.Succeeded || person.Data.PushDisabled) { continue; } string email = user.Data.Identities.FirstOrDefault()?.IssuerAssignedId; if (email == null) { continue; } StringBuilder sb = new StringBuilder(); string DateFormat = "yyyyMMddTHHmmssZ"; string now = DateTime.Now.ToUniversalTime().ToString(DateFormat); sb.AppendLine("BEGIN:VCALENDAR"); sb.AppendLine("PRODID:-//Compnay Inc//Product Application//EN"); sb.AppendLine("VERSION:2.0"); sb.AppendLine("METHOD:PUBLISH"); string body = null; foreach (Availability availability in participation.Availabilities .Where(a => a.Type == AvailibilityType.Scheduled && !a.PushEmailSend) .OrderBy(a => a.Shift.Date)) { DateTime dtStart = availability.Shift.Date + availability.Shift.StartTime; DateTime dtEnd = availability.Shift.Date + availability.Shift.EndTime; string description = availability.Shift.Task != null ? availability.Shift.Task.Description : "Onbekende omschrijving"; string taskName = availability.Shift.Task != null ? availability.Shift.Task.Name : "Onbekend"; sb.AppendLine("BEGIN:VEVENT"); sb.AppendLine("DTSTART:" + dtStart.ToUniversalTime().ToString(DateFormat)); sb.AppendLine("DTEND:" + dtEnd.ToUniversalTime().ToString(DateFormat)); sb.AppendLine("DTSTAMP:" + now); sb.AppendLine("UID:" + Guid.NewGuid()); sb.AppendLine("CREATED:" + now); sb.AppendLine("X-ALT-DESC;FMTTYPE=text/html:" + description); //sb.AppendLine("DESCRIPTION:" + res.Details); sb.AppendLine("LAST-MODIFIED:" + now); sb.AppendLine("LOCATION:" + participation.Project.Address + " " + participation.Project.City); sb.AppendLine("SEQUENCE:0"); sb.AppendLine("STATUS:CONFIRMED"); sb.AppendLine("SUMMARY:" + taskName); sb.AppendLine("TRANSP:OPAQUE"); sb.AppendLine("END:VEVENT"); if (body == null) { body += "Beste " + user.Data.DisplayName + ",<br><br>"; body += "Je bent zojuist ingeroosterd voor de volgende diensten:<br><br>"; } body += "<b>" + availability.Shift.Date.ToString("dddd, dd MMMM yyyy", culture) + " - " + taskName + "</b><br>" + "Van: " + availability.Shift.StartTime.ToString("hh\\:mm") + "uur<br>" + "Tot: " + availability.Shift.EndTime.ToString("hh\\:mm") + "uur<br><br>"; //change attribute in db availability.PushEmailSend = true; } sb.AppendLine("END:VCALENDAR"); var calendarBytes = Encoding.UTF8.GetBytes(sb.ToString()); MemoryStream ms = new MemoryStream(calendarBytes); System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(ms, "event.ics", "text/calendar"); await participationService.UpdateParticipationAsync(participation); if (body == null) { continue; } body += "Bekijk via <u><a href=\"" + webUrlConfig.Url + "/schedule/" + participation.Id + "\">deze link</a></u> alle shifts waarvoor je staat ingeroosterd.<br>"; body += "Via deze pagina kun je ook de beschrijving en instructies voor je shift zien.<br><br>"; body += "Hartige groetjes en tot ziens!"; participationService.SendEmail(email, "Je bent ingeroosterd", body, true, null, attachment); } return(Ok()); } catch (Exception ex) { string message = GetType().Name + "Error in " + nameof(SendEmailAsync); logger.LogError(ex, message); return(UnprocessableEntity(new ErrorViewModel { Type = Type.Error, Message = message })); } }