public async Task <IActionResult> Create([Bind("StaffId,Staff,EventId,Event")] Staffing staff) { var selectedStaff = _eventContext.Staffing .Include(a => a.Event) .Include(a => a.Staff) .FirstOrDefault(a => a.StaffId == staff.StaffId && a.EventId == staff.EventId); if (ModelState.IsValid) { try { _eventContext.Add(staff); await _eventContext.SaveChangesAsync(); return(RedirectToAction(nameof(StaffingIndex))); } catch (InvalidOperationException) { TempData["msg"] = $"Error : {selectedStaff.Staff.Fullname} and {selectedStaff.Event.Title} already existed!"; } catch (Exception ex) { TempData["msg"] = ex.Message; } } else { TempData["msg"] = "ModelState is not valid, please verify guestbooking model"; } ViewData["StaffId"] = new SelectList(_eventContext.Staff, "StaffId", "Fullname", staff.Staff); ViewData["EventId"] = new SelectList(_eventContext.Events, "Id", "Title", staff.Event); return(View(staff)); }
public async Task <IActionResult> Create([Bind("StaffId,EventId")] Staffing staffing) { if (ModelState.IsValid) { //Check if staffing already exists if (_context.Workers.Any(w => w.StaffId == staffing.StaffId && w.EventId == staffing.EventId)) { ModelState.AddModelError(string.Empty, "Booking already exists"); } else { _context.Add(staffing); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Events", new { id = staffing.EventId })); } } var @event = await _context.Events.FindAsync(staffing.EventId); if (@event == null) { return(BadRequest()); } ViewData["EventTitle"] = @event.Title; staffing.Staff.Jobs.Add(staffing); staffing.Event.Staff.Add(staffing); return(View(staffing)); }
public async Task <IActionResult> Edit(int id, [Bind("StaffId,EventId")] Staffing staffing) { if (id != staffing.StaffId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(staffing); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StaffingExists(staffing.StaffId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffing.EventId); ViewData["StaffId"] = new SelectList(_context.Staff, "Id", "Id", staffing.StaffId); return(View(staffing)); }
public HttpResponseMessage Get(int id) { using (var session = NHibernateHelper.CreateSessionFactory()) { using (var transaction = session.BeginTransaction()) { Staffing entity; if (id == 0) { entity = new Staffing(); } else { // collect objects var data = new List <Staffing>(session.CreateCriteria(typeof(Staffing)).List <Staffing>()); // collect single object entity = data.FirstOrDefault(x => x.Id == id); } // trim excess if (entity != null) { } // return as HttpResponseMessage return(WebApiHelper.ObjectToHttpResponseMessage(entity)); } } }
public async Task <IActionResult> StaffingDetails(int?id) { if (id == null) { return(NotFound()); } var @staffing = await _context.Staffing .FirstOrDefaultAsync(e => e.EventId == id); if (@staffing == null) { ViewBag.NoStaff = true; staffing = new Staffing(); staffing.EventId = id.Value; staffing.Event = await _context. Events.FirstOrDefaultAsync(e => e.Id == id); Debug.WriteLine("No staff"); } ViewBag.Staffing = true; return(View("_StaffList", staffing)); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Create([Bind("StaffId,EventId,Attended")] StaffBookingVM staffAttendance) { if (ModelState.IsValid) { try { Staffing staff = await _context.Staffing.FindAsync(staffAttendance.StaffId, staffAttendance.EventId); if (staff != null && staffAttendance.Attended == false) { _context.Remove(staff); await _context.SaveChangesAsync(); return(Ok()); } if (staff == null && staffAttendance.Attended == true) { _context.Add(new Staffing(staffAttendance.EventId, staffAttendance.StaffId)); await _context.SaveChangesAsync(); return(Ok()); } } catch (DbUpdateConcurrencyException) { } } return(NotFound()); }
public void AddMethodOK() { //Create an instance of the collections class StaffingCollection aStaffCollection = new StaffingCollection(); //create an instance of test data Staffing TestItem = new Staffing(); //Primary key storage Int32 primaryKey = 0; //Initiate properties of test data TestItem.staffName = new Name("Thomas", "Barnes"); TestItem.staffNumber = "01706844505"; TestItem.staffEmail = "*****@*****.**"; TestItem.staffDOB = Convert.ToDateTime("08/09/1990"); TestItem.staffValid = true; //Set test data into collections aStaffCollection.ThisStaff = TestItem; //Add the record primaryKey = aStaffCollection.Add(); //Set the primary key of the test data TestItem.staffID = primaryKey; //Find the record aStaffCollection.ThisStaff.Find(primaryKey); //Test to see that the two values are the same Assert.AreEqual(aStaffCollection.ThisStaff, TestItem); }
public void AssertNotNull() { //create instance of the class we want to create Staffing s1 = new Staffing(); //test to see that it now exists Assert.IsNotNull(s1); }
public void TestName() { //Create an instance of name and staffing Name n1 = new Name("Jimmy", "McBro"); Staffing s1 = new Staffing(); //Insert the test name s1.staffName = n1; //Compare if equal Assert.AreEqual(n1, s1.staffName); }
protected void Page_Load(object sender, EventArgs e) { //Create a new instance of staff Staffing staff = new Staffing(); //get the data from the session object staff = (Staffing)Session["staff"]; //Display the email for this staff //Response.Write(staff.getEmail()); }
public void TestID() { //create instance of the class we want to create Staffing s2 = new Staffing(); //create some test data to assign to staff int Test = 1; //assign the data to the Staff s2.staffID = Test; //test to see that the two values are the same Assert.AreEqual(Test, s2.staffID); }
public async Task <IActionResult> Delete([Bind("StaffId,EventId")] Staffing staffing) { var worker = await _context.Workers .Where(w => w.EventId == staffing.EventId) .Where(w => w.StaffId == staffing.StaffId) .FirstOrDefaultAsync(); _context.Workers.Remove(worker); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Events", new { id = staffing.EventId })); }
public void TestEmail() { //create instance of the class we want to create Staffing s2 = new Staffing(); //create some test data to assign to tutor string Test = "*****@*****.**"; //assign the data to the Staff s2.staffEmail = Test; //test to see that the two values are the same Assert.AreEqual(Test, s2.staffEmail); }
public void TestValid() { //create instance of the class we want to create Staffing s2 = new Staffing(); //create some test data to assign to staff bool Test = true; //assign the data to the Staff s2.staffValid = Test; //test to see that the two values are the same Assert.AreEqual(Test, s2.staffValid); }
public void TestNumber() { //create instance of the class we want to create Staffing s2 = new Staffing(); //create some test data to assign to staff string Test = "01706844505"; //assign the data to the Staff s2.staffNumber = Test; //test to see that the two values are the same Assert.AreEqual(Test, s2.staffNumber); }
public void ValidMethodOK() { //create an instance of staff Staffing aStaff = new Staffing(); //string variable to store any error message String Error = ""; //invoke the method //We ignore staffValid as it only can contain a boolean value Error = aStaff.Valid(staffFN, staffLN, staffEmail, staffNumber, staffDOB); //Test to see if the result is correct Assert.AreEqual(Error, ""); }
public async Task <IActionResult> Create([Bind("StaffId,EventId")] Staffing staffing) { if (ModelState.IsValid) { _context.Add(staffing); await _context.SaveChangesAsync(); return(RedirectToAction("Index", nameof(Event))); } ViewData["EventId"] = new SelectList(_context.Events, "Id", "Title", staffing.EventId); ViewData["StaffId"] = new SelectList(_context.Staff, "Id", "FirstName", staffing.StaffId); return(RedirectToAction("Index", nameof(Event))); }
public async Task <IActionResult> Create([Bind("EventID,StaffID")] Staffing staffing) { if (ModelState.IsValid) { _context.Add(staffing); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["EventID"] = new SelectList(_context.Events, "Id", "Title", staffing.EventID); ViewData["StaffID"] = new SelectList(_context.Staffs, "StaffID", "StaffEmail", staffing.StaffID); return(View(staffing)); }
public async Task <IActionResult> Create([Bind("StaffId,EventId")] Staffing staffing) { if (ModelState.IsValid) { _context.Add(staffing); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["EventId"] = new SelectList(_dataAccess.GetEvents(), "Id", "Title", staffing.EventId); ViewData["StaffId"] = new SelectList(await _context.Staff.ToListAsync(), "Id", "Id", staffing.StaffId); return(View(staffing)); }
public HttpResponseMessage Post(Staffing entity) { using (var session = NHibernateHelper.CreateSessionFactory()) { using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(entity); transaction.Commit(); // return as HttpResponseMessage return(WebApiHelper.ObjectToHttpResponseMessage(entity)); } } }
// GET: From Event to StaffBooking public IActionResult CreateStaffEvent(int eventid) { ViewData["StaffId"] = new SelectList(_eventContext.Staff, "StaffId", "Fullname"); ViewData["EventId"] = new SelectList(_eventContext.Events, "Id", "Title", eventid); var @event = _eventContext.Events.FirstOrDefault(a => a.Id == eventid); Staffing staff = new Staffing() { Event = @event, EventId = @event.Id, }; return(View(staff)); }
public void StaffEmailMid() { //Create an instance of staffing Staffing aStaff = new Staffing(); //string variable to store any error message String Error = ""; //Test data to pass the method string Email = "*****@*****.**"; //Invoke the method Error = aStaff.Valid(staffFN, staffLN, Email, staffNumber, staffDOB); //test to see that the result is correct Assert.AreEqual(Error, ""); }
public void FindMethodOK() { //Create an instance of Staffing Staffing staffT = new Staffing(); //Boolean varibable to store the result of the validation Boolean Found = false; //Create some test data to use with the method Int32 staffID = 14; //Invoke the method Found = staffT.Find(staffID); //Test to see if ther esult is correct Assert.IsTrue(Found); }
public void StaffFirstNameMinLessOne() { //Create an instance of staffing Staffing aStaff = new Staffing(); //string variable to store any error message String Error = ""; //Test data to fail the method string FirstName = ""; //Invoke the method Error = aStaff.Valid(FirstName, staffLN, staffEmail, staffNumber, staffDOB); //test to see that the result is correct Assert.AreNotEqual(Error, ""); }
public void DOBInvalidData() { //Create an instance of staffing Staffing aStaff = new Staffing(); //string variable to store any error message String Error = ""; //set StaffDOB to a non date data type string staffDOBTest = "this is not a date"; //Invoke the method Error = aStaff.Valid(staffFN, staffLN, staffEmail, staffNumber, staffDOBTest); //test to see that the result is correct Assert.AreNotEqual(Error, ""); }
public void StaffLastNameMaxMinusOne() { //Create an instance of staffing Staffing aStaff = new Staffing(); //string variable to store any error message String Error = ""; //Test data to pass the method string LastName = "Aaaaaaaaaaaaaa"; //Invoke the method Error = aStaff.Valid(staffFN, LastName, staffEmail, staffNumber, staffDOB); //test to see that the result is correct Assert.AreEqual(Error, ""); }
public void StaffNumberMaxPlusOne() { //Create an instance of staffing Staffing aStaff = new Staffing(); //string variable to store any error message String Error = ""; //Test data to pass the method string Number = "013865391025"; //Invoke the method Error = aStaff.Valid(staffFN, staffLN, staffEmail, Number, staffDOB); //test to see that the result is correct Assert.AreNotEqual(Error, ""); }
public void StaffEmailExtremeMax() { //Create an instance of staffing Staffing aStaff = new Staffing(); //string variable to store any error message String Error = ""; //Test data to pass the method string Email = "*****@*****.**"; Email = Email.PadRight(470, 'a'); //Invoke the method Error = aStaff.Valid(staffFN, staffLN, Email, staffNumber, staffDOB); //test to see that the result is correct Assert.AreNotEqual(Error, ""); }
protected void OkButton_Click(object sender, EventArgs e) { //Create a new instance of staff Staffing staff = new Staffing(); //String to store any error messages String Error = ""; //Validate the data Error = staff.Valid(txtFirstName.Text, txtLastName.Text, txtEmail.Text, txtNumber.Text, txtDOB.Text); if (Error == "") { //capture the staff ID staff.staffID = StaffID; //Capture the Staff name staff.staffName = new Name(txtFirstName.Text, txtLastName.Text); //Capture the email staff.staffEmail = txtEmail.Text; //Capture the staff staff.staffNumber = txtNumber.Text; //Capture the staff DOB staff.staffDOB = Convert.ToDateTime(txtDOB.Text); //Capture the staff Validity staff.staffValid = StaffValid.Checked; //Create a new instance of the staffing collection StaffingCollection staffList = new StaffingCollection(); if (StaffID == -1) { staffList.ThisStaff = staff; staffList.Add(); } else { staffList.ThisStaff.Find(StaffID); staffList.ThisStaff = staff; staffList.Update(); } //redirect to the aTutor page Response.Redirect("Staffing_List.aspx"); } else { txtError.Visible = true; //display the error message txtError.Text = "Error! " + Error; } }
public VacationListItemViewModel(Staffing.EmployeeViewModel employee, VacationsViewModel owner) { if (employee == null) throw new ArgumentNullException(nameof(employee)); if (owner == null) throw new ArgumentNullException(nameof(owner)); Employee = employee; Owner = owner; Balance = owner.VacationBalances.FirstOrDefault(b => b.EmployeeId == Employee.Employee.Id); owner.VacationBalances.CollectionChanged += (_, e) => { var itm = e.OldItems? .Cast<VacationService.VacationBalance>() .FirstOrDefault(i => i.EmployeeId == employee.Employee.Id); if (itm != null) Balance = null; itm = e.NewItems? .Cast<VacationService.VacationBalance>() .FirstOrDefault(i => i.EmployeeId == employee.Employee.Id); if (itm != null) Balance = itm; }; foreach (var item in Owner.Vacations.Where(v => v.EmployeeId == Employee.Employee.Id)) vacations.Add(new VacationListItemPartViewModel(this, item)); Owner.Vacations.CollectionChanged += (_, e) => { if (e.OldItems != null) foreach (var oldItem in e.OldItems .Cast<VacationService.Vacation>() .Where(i => i.EmployeeId == employee.Employee.Id) .Join(vacations, v => v, vm => vm.Vacation, (v, vm) => vm)) vacations.Remove(oldItem); if (e.NewItems != null) foreach (var newItem in e.NewItems .Cast<VacationService.Vacation>() .Where(i => i.EmployeeId == employee.Employee.Id) .Select(i => new VacationListItemPartViewModel(this, i))) vacations.Add(newItem); }; }
protected void Page_Load(object sender, EventArgs e) { //Create a new instance of staff Staffing staff = new Staffing(); //Get the data from the session object staff = (Staffing)Session["staff"]; Response.Write("<b> LOGIN SUCCESSFUL </b>"); //Display what text is in each field lblFirstName.Text = staff.staffName.getFirstName(); lblLastName.Text = staff.staffName.getLastName(); lblEmail.Text = staff.staffEmail; lblNumber.Text = staff.staffNumber; lblDOB.Text = staff.staffDOB.ToString(); lblValid.Text = staff.staffValid.ToString(); }
private void Load(Staffing.StaffingViewModel model) { IsLoaded = false; Notifications?.Add(new ServiceWorkers.NotificationItem( header: Properties.Resources.ERROR, message: Properties.Resources.UNLOADED, isError: false, iconUrl: ServiceWorkers.AbstractBaseWorker.IconUrlByType(GetType(), ServiceCultureInfo) )); try { Clear(); if (model == null) return; var dtNow = DateTime.Now; var now = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day); //var start = now - TimeSpan.FromDays(Period.TotalDays / 2d); //var end = start + Period; var departments = model.Departments.AsEnumerable().Traverse(i => i.Childs).Select(i => i.Data.Department); #region Today var employeesToday = model.Employees .Where(e => e.Employee.Birthday.HasValue) .Select(e => new { EmployeeVM = e, YearBirthday = GetEmployeeDateBirthFor(now, now, e.Employee.Birthday.Value) }) .Where(e => e.YearBirthday.HasValue) .OrderBy(r => r.YearBirthday.Value) .Select(e => new EmployeeViewModel() { Employee = e.EmployeeVM.Employee, Department = e.EmployeeVM.Department, Age = e.YearBirthday.Value.Year - e.EmployeeVM.Employee.Birthday.Value.Year, DayOfBirthday = e.YearBirthday.Value, }); #endregion levels.Clear(); var weekLevel = GetWeekLevel(model, PeriodForWeek); var monthLevel = GetMonthLevel(model, PeriodForMonth); var month3Level = GetMonth3Level(model, PeriodForMonth + PeriodForMonth + PeriodForMonth); var yearLevel = GetYearLevel(model, PeriodForYear); foreach (var level in new[] { weekLevel, monthLevel, month3Level, yearLevel }.OrderByDescending(p => p.Period)) levels.Add(level); SelectedLevel = Levels.LastOrDefault(); IsLoaded = true; Notifications?.Add(new ServiceWorkers.NotificationItem( header: Properties.Resources.ERROR, message: Properties.Resources.LOADED, isError: false, iconUrl: ServiceWorkers.AbstractBaseWorker.IconUrlByType(GetType(), ServiceCultureInfo) )); } catch (Exception ex) { Notifications?.Add(new ServiceWorkers.NotificationItem( header: Properties.Resources.ERROR, message: ServiceWorkers.AbstractBaseWorker.GetExceptionText(ex), isError: true, iconUrl: ServiceWorkers.AbstractBaseWorker.IconUrlByType(GetType(), ServiceCultureInfo) )); } finally { RaiseCommands(); } }
private static LevelViewModel GetYearLevel(Staffing.StaffingViewModel model, TimeSpan period) { return GetLevel(model, period, Properties.Resources.VMBIRTHDAYS_BYYEAR, start => start - TimeSpan.FromDays(start.DayOfYear - 1), dt => dt.ToString("yyyy"), dt => dt.AddYears(1)); }
private static LevelViewModel GetMonth3Level(Staffing.StaffingViewModel model, TimeSpan period) { return GetLevel(model, period, Properties.Resources.VMBIRTHDAYS_BY3MONTH, start => start - TimeSpan.FromDays(start.Day - 1), dt => dt.ToString("MMMMMM yyyy"), dt => dt.AddMonths(3)); }
private static LevelViewModel GetWeekLevel(Staffing.StaffingViewModel model, TimeSpan period) { return GetLevel(model, period, Properties.Resources.VMBIRTHDAYS_BYWEEK, start => start - TimeSpan.FromDays((int)start.DayOfWeek + 1), dt => $"{dt.Year}/{dt.DayOfYear / 7}", dt => dt.AddDays(7)); }
private static LevelViewModel GetDayLevel(Staffing.StaffingViewModel model, TimeSpan period) { return GetLevel(model, period, Properties.Resources.VMBIRTHDAYS_BYDAY, start => start, dt => dt.ToShortDateString(), dt => dt.AddDays(1)); }
private static LevelViewModel GetLevel( Staffing.StaffingViewModel model, TimeSpan period, string name, Func<DateTime, DateTime> changeStartPeriodDate, Func<DateTime, string> getTimePartName, Func<DateTime, DateTime> getNextPeriodStartDate ) { var level = new LevelViewModel() { Name = name, Period = period }; if (model == null) return level; var dtNow = DateTime.Now; var now = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day); var start = now - TimeSpan.FromDays(period.TotalDays / 2d); var end = start + period; var departments = model.Departments.AsEnumerable().Traverse(i => i.Childs).Select(i => i.Data.Department); var periodStart = changeStartPeriodDate(start); periodStart = new DateTime(periodStart.Year, periodStart.Month, periodStart.Day); var getName = new Func<DateTime, DateTime, string>((dt0, dt1) => { var nameStart = getTimePartName(dt0); var nameEnd = getTimePartName(dt1); return (nameStart == nameEnd) ? nameStart : $"{nameStart} - {nameEnd}"; }); while (periodStart < end) { var periodEnd = getNextPeriodStartDate(periodStart).AddDays(-1); // periodStart + TimeSpan.FromDays(7); var tp = new TimePartViewModel() { Start = periodStart, End = periodEnd, IsCurrent = periodStart <= now && now <= periodEnd, Name = getName(periodStart, periodEnd) }; var employees = model.Employees .Where(e => e.Employee.Birthday.HasValue) .Select(e => new { EmployeeVM = e, YearBirthday = GetEmployeeDateBirthFor(tp.Start, tp.End, e.Employee.Birthday.Value) }) .Where(e => e.YearBirthday.HasValue) .OrderBy(r => r.YearBirthday.Value) .Select(e => new EmployeeViewModel() { Employee = e.EmployeeVM.Employee, Department = e.EmployeeVM.Department, Age = e.YearBirthday.Value.Year - e.EmployeeVM.Employee.Birthday.Value.Year, DayOfBirthday = e.YearBirthday.Value, }); foreach (var e in employees) tp.Employee.Add(e); level.Parts.Add(tp); periodStart = periodEnd.AddDays(1); } for (int i = level.Parts.Count - 1; i >= 1; i--) if (level.Parts[i].Employee.Count == 0 && level.Parts[i - 1].Employee.Count == 0) { level.Parts[i - 1].End = level.Parts[i].End; level.Parts[i - 1].IsCurrent |= level.Parts[i].IsCurrent; level.Parts[i - 1].Name = getName(level.Parts[i - 1].Start, level.Parts[i - 1].End); level.Parts.RemoveAt(i); } return level; }