// POST api/<controller> public void Post(VolunteerActivity activity) { var currentUser = repo.GetUserByUserName(User.Identity.Name); activity.VolunteerUser = currentUser; repo.AddActivity(activity); }
/* * GET ONE ACTIVITY * This method gets the activity by the activityId from the database. * The ActivitiesController GET method that takes an argument is the * one used here. * * Arguments: * ActivityId - the id of the activity */ public VolunteerActivity GetActivityById(int activity_Id) { VolunteerActivity found_activity = Context.Activities.FirstOrDefault(i => i.ActivityId == activity_Id); if (found_activity != null) { return(found_activity); } else { return(null); } }
public async void DoClockout(Volunteer ourVolunteer, Boolean after) { VolunteerActivity LastActivity = await GetLastActivity(ourVolunteer); if (!after) { LastActivity.EndTime = DateTime.Now; } LastActivity.ClockedIn = false; _context.Attach(LastActivity).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public IActionResult OnPostClockOut() { //Move over the clock in code here Volunteer ourVolunteer = null; VolunteerActivity LastActivity = null; try { ourVolunteer = (from volunteer in _context.Volunteer where volunteer.Email.ToLower().Trim() == Volunteers.Email.ToLower().Trim() select volunteer).ToList()[0]; LastActivity = GetLastActivity(ourVolunteer); if (LastActivity != null) { if (LastActivity.ClockedIn) { DoClockout(ourVolunteer, false); if (DateTime.Compare(LastActivity.StartTime, DateTime.Now) > 0) { DoClockout(ourVolunteer, false); _log.LogInformation($"{ourVolunteer.Email} clocked out"); } else { DoClockout(ourVolunteer, true); _log.LogInformation($"{ourVolunteer.Email} clocked out"); } TempData["message"] = "CO"; } else { TempData["message"] = "NCI"; } } else { TempData["message"] = "NCI"; } } catch { TempData["message"] = "UNF"; } System.Threading.Thread.Sleep(500); return(RedirectToPage("./Index")); }
//志愿者参与的志愿活动(已结束和进行中)(必须有签到记录) 参数 志愿者VID public List <VolunteerActivitySearchMiddle> GetMyAllActivity(string VID) { List <String> Infos = _IVA_SignRepository.GetMyList(VID); List <VolunteerActivitySearchMiddle> Searches = new List <VolunteerActivitySearchMiddle>(); foreach (var item in Infos) { VolunteerActivity middle = new VolunteerActivity(); middle = _IVolunteerActivityRepository.GetByID(item.ToString()); var SearchMiddlecs = _IMapper.Map <VolunteerActivity, VolunteerActivitySearchMiddle>(middle); Searches.Add(SearchMiddlecs); } return(Searches); }
public async Task <IActionResult> OnPostClockOutAsync() { Console.WriteLine("Clocking in"); //Move over the clock in code here Volunteer ourVolunteer = null; VolunteerActivity LastActivity = null; try { ourVolunteer = (await(from volunteer in _context.Volunteer where volunteer.Email.ToLower().Trim() == Volunteers.Email.ToLower().Trim() select volunteer).ToListAsync())[0]; LastActivity = await GetLastActivity(ourVolunteer); if (LastActivity != null) { if (LastActivity.ClockedIn) { DoClockout(ourVolunteer, false); if (DateTime.Compare(LastActivity.StartTime, DateTime.Now) > 0) { DoClockout(ourVolunteer, false); } else { DoClockout(ourVolunteer, true); } TempData["message"] = "CO"; } else { TempData["message"] = "NCI"; } } else { TempData["message"] = "NCI"; } } catch { TempData["message"] = "UNF"; } System.Threading.Thread.Sleep(500); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostClockInAsync() { try { //Find our volunteer and their last activity Volunteer ourVolunteer = (from volunteer in _context.Volunteer where volunteer.Email.ToLower().Trim() == Volunteers.Email.ToLower().Trim() select volunteer).ToList()[0]; VolunteerActivity LastActivity = await GetLastActivity(ourVolunteer); if (LastActivity != null && !LastActivity.ClockedIn) { Clockin(ourVolunteer); //Send a toast to the user saying Clocked in TempData["message"] = "CI"; System.Threading.Thread.Sleep(500); } else if (LastActivity != null && LastActivity.ClockedIn) { if (DateTime.Compare(LastActivity.EndTime, DateTime.Now) > 0) { //Send a toast to the user saying Not clocked out TempData["message"] = "NCO"; System.Threading.Thread.Sleep(500); } else { DoClockout(ourVolunteer, true); Clockin(ourVolunteer); TempData["message"] = "CI"; System.Threading.Thread.Sleep(500); } } else { Clockin(ourVolunteer); TempData["message"] = "CI"; System.Threading.Thread.Sleep(500); } } catch { TempData["message"] = "UNF"; } return(RedirectToPage("./Index")); }
public void EnsureCanAddActivity() { //Arrange ConnectToDatastore(); //Act VolunteerActivity a_activity = new VolunteerActivity { ActivityId = 1, OrgName = "American Red Cross", NumberHours = 4, Mileage = 14, DollarsContributed = 100 }; //int actual_activities = 0; Repo.AddActivity(a_activity); int expected_activities = 3; int actual_activities = Repo.Context.Activities.Count(); //Assert Assert.AreEqual(expected_activities, actual_activities); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } VolunteerActivity = await _context.VolunteerActivity .Include(v => v.Volunteer).FirstOrDefaultAsync(m => m.VolunteerActivityID == id); if (VolunteerActivity == null) { return(NotFound()); } ViewData["VolunteerId"] = new SelectList(_context.Volunteer, "VolunteerID", "FullName"); var ValidInitiatives = from i in _context.Initiative where i.InActive == false orderby i.Description // Sort by name. select i; ViewData["InitiativeId"] = new SelectList(ValidInitiatives, "InitiativeID", "Description"); return(Page()); }
private static int AddDataToTable(IWTable info, int row, VolunteerActivity activity, DbSet <Initiative> initiatives) { info.AddRow(); row += 1; info.Rows[row].Height = 20; string Start = activity.StartTime.ToString(); string End = activity.EndTime.ToString(); var StartAMPM = activity.StartTime.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture); var EndAMPM = activity.EndTime.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture); int id = activity.InitiativeId; info.Rows[row].Cells[0].AddParagraph().AppendText(Start.Split(' ')[0]); info.Rows[row].Cells[1].AddParagraph().AppendText(initiatives.Single(m => m.InitiativeID == id).Description); // info.Rows[row].Cells[2].AddParagraph().AppendText(Start.Split(' ')[1]); info.Rows[row].Cells[2].AddParagraph().AppendText(StartAMPM); info.Rows[row].Cells[3].AddParagraph().AppendText(EndAMPM); // info.Rows[row].Cells[3].AddParagraph().AppendText(End.Split(' ')[1]); info.Rows[row].Cells[4].AddParagraph().AppendText(activity.ElapsedTime.ToString().Split('.')[0]); return(row); }
public virtual void Update(VolunteerActivity obj) { DbSet.Update(obj); }
public virtual void Add(VolunteerActivity obj) { DbSet.Add(obj); }
/* * UPDATE ACTIVITY * This method edits a volunteer activity from the database. * This is accomplished by the PUT method in the C# * ActivitiesController. * * Arguments: * Activity - the activity that the user clicks the edit button for, * while on the MyActivities page, Activities.cshtml. */ public void UpdateActivity(VolunteerActivity _activity) { Context.Entry(_activity).State = System.Data.Entity.EntityState.Modified; Context.SaveChanges(); }
/* * ADD ACTIVITY * This method adds a volunteer activity to the database. * This is accomplished by the POST method in the C# * ActivitiesController. * * Arguments: * Activity - the user inputs the activity on the InputActivity.cshtml page. */ public void AddActivity(VolunteerActivity _activity) { Context.Activities.Add(_activity); Context.SaveChanges(); }
// PUT api/<controller> public void Put(int Id, [FromBody] VolunteerActivity value) { var foundActivityForUpdate = repo.GetActivityById(Id); repo.UpdateActivity(value); }
/// <summary> /// Create a new RequestsActivity view and parse each request and add each component to its respective list /// </summary> /// <returns>The create view.</returns> /// <param name="inflater">Inflater</param> /// <param name="container">Container</param> /// <param name="savedInstanceState">Saved instance state</param> public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Dialog.Window.RequestFeature(WindowFeatures.NoTitle); //remove the title from the dialog fragment base.OnCreate(savedInstanceState); Dialog.Window.SetLayout(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); //set the layout of the dialog fragment view = inflater.Inflate(Resource.Layout.Requests, container, false); //initialize each variable to its view component name = (TextView)view.FindViewById(Resource.Id.userName); toLocation = (TextView)view.FindViewById(Resource.Id.toLocation); fromLocation = (TextView)view.FindViewById(Resource.Id.fromLocation); additionalInfo = (TextView)view.FindViewById(Resource.Id.additionalInfo); ImageButton rightArrow = (ImageButton)view.FindViewById(Resource.Id.rightArrow); ImageButton leftArrow = (ImageButton)view.FindViewById(Resource.Id.leftArrow); ImageButton closeBtn = (ImageButton)view.FindViewById(Resource.Id.closeButton); Button acceptReq = (Button)view.FindViewById(Resource.Id.acceptRequest); ProgressBar loadingSpinner = (ProgressBar)view.FindViewById(Resource.Id.spinner1); loadingSpinner.Visibility = ViewStates.Gone; //Take care of correct fonts Typeface bentonSans = Typeface.CreateFromAsset(this.Activity.Application.Assets, "BentonSansRegular.otf"); setFont(bentonSans, name); setFont(bentonSans, toLocation); setFont(bentonSans, fromLocation); setFont(bentonSans, additionalInfo); currentCount = 0; //set the initial count to zero //if there exists more than 1 request if (activeRequests.Count > 1) { setInfo(activeRequests[currentCount]); //set the current info disableArrow(leftArrow); //disable the left arrow //left arrow click listener leftArrow.Click += (sender, e) => { enableArrow(rightArrow); //enable the right arrow currentCount--; //decrease the current count if (currentCount == 0) { disableArrow(leftArrow); //if the count is 0, no more requests to the left } setInfo(activeRequests[currentCount]); //set the current info }; //right arrow click listener rightArrow.Click += (sender, e) => { enableArrow(leftArrow); //enable the left arrow currentCount++; //increase the current count if (currentCount == reqCount - 1) { disableArrow(rightArrow); //if it is the last request, no more requests to the right } setInfo(activeRequests[currentCount]); //set the current info }; } else //if there is only 1 request { //disable both arrows disableArrow(leftArrow); disableArrow(rightArrow); setInfo(activeRequests[0]); //set info of the only request } //close button click listener closeBtn.Click += (sender, e) => { dismissFragment(); //close the dialog fragment }; //accept request button click listener acceptReq.Click += (sender, e) => { loadingSpinner.Visibility = ViewStates.Visible; va = new VolunteerActivity(); //initialize the new instance of the VolunteerActivity class va.onTripAcceptAsync(activeRequests[currentCount]); //pass the accepted request into the trip accept function }; return(view); }