public async Task Should_return_all_exhibits() { var exhibitCommand = new Create.Command { GenreId = 1, UserId = "id", Location = "aperture gallery", DateTime = DateTime.Today, ImageUrl = "url" }; var exhibit = Exhibit.Create(exhibitCommand); var attendanceCommand = new Attend.Command { UserId = _attendeeId, ExhibitId = _exhibitId }; var attendance = Attendance.Create(attendanceCommand); exhibit.AddAttendance(attendance); await InsertAsync(exhibit); var result = await SendAsync(new Index.Query()); result.ShouldNotBeNull(); }
public async Task <JsonResult> CheckInOut(Guid personId, Guid?classId) { var startDate = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day); var endDate = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day, 23, 59, 59); var inAttendance = await _unitOfWork.Attendances.GetOneAsync(x => x.IsActive && x.PersonId == personId && x.ClassId == classId && x.InDate >= startDate && x.InDate <= endDate); //Checkout if (inAttendance != null) { if (inAttendance.OutDate.HasValue) { return(Json(new JsonMessage { Color = "#ff0000", Message = "Person already checked out", Header = "Error", Icon = "error" })); } else { inAttendance.OutDate = DateTime.UtcNow; _unitOfWork.Attendances.Update(inAttendance); var result = await _unitOfWork.SaveAsync(); if (result.Succeeded) { return(Json(new JsonMessage { Color = "#ff6849", Message = "Person checked out", Header = "Success", Icon = "success", AdditionalData = new { id = personId } })); } return(Json(new JsonMessage { Color = "#ff0000", Message = "Error", Header = "Error", Icon = "error" })); } } //Checkin else { var attendance = Attendance.Create(personId, classId, _organizationId, _userId); await _unitOfWork.Attendances.Insert(attendance); var result = await _unitOfWork.SaveAsync(); if (result.Succeeded) { return(Json(new JsonMessage { Color = "#ff6849", Message = "Person checked in", Header = "Success", Icon = "success" })); } return(Json(new JsonMessage { Color = "#ff0000", Message = "Error", Header = "Error", Icon = "error" })); } }
public Result Handle(Command message) { var exhibit = _exhibitRepository.GetExhibit(message.ExhibitId); if (exhibit == null) { return(Result.Fail <int> ("Exhibit does not exit")); } var contains = exhibit.Attendances.Any(a => a.AttendeeId == message.UserId); if (contains == true) { return(Result.Fail <Command> ("Attendance already exists.")); } exhibit.AddAttendance(Attendance.Create(message)); _exhibitRepository.SaveAll(); return(Result.Ok()); }
public void IsReadIsTrue() { var exhibitCommand = new Create.Command { GenreId = 1, UserId = "id", Location = "aperture gallery", DateTime = DateTime.Today, ImageUrl = "url" }; var exhibit = Exhibit.Create(exhibitCommand); var attendanceCommand = new Attend.Command { UserId = _attendeeId, ExhibitId = _exhibitId }; var attendance = Attendance.Create(attendanceCommand); exhibit.AddAttendance(attendance); Assert.Equal(_exhibitId, exhibit.Attendances.SingleOrDefault().ExhibitId); Assert.Equal(_attendeeId, exhibit.Attendances.SingleOrDefault().AttendeeId); }
public ContentResult AddAll(FormCollection form) { // add new attendance row for all employees JObject json = new JObject(); json["error"] = false; json["message"] = ""; string[] keys = new string[] { "v" }; int count = 0; if (this.HasValues(form, keys)) { if (!this.CheckLogin(AccountType.Applicant) && ((Employee)this.GetAccount().Profile).Department.Type == DepartmentType.HumanResources) { try { DBHandler db = new DBHandler(); using (DataTable dt = db.Execute <DataTable>( CRUD.READ, "SELECT Profile FROM Account WHERE Type = " + ((int)AccountType.Employee) + " OR Type = " + ((int)AccountType.DepartmentHead))) { foreach (DataRow row in dt.Rows) { Employee emp = new Employee(Int32.Parse(row["Profile"].ToString())); Attendance at = new Attendance(); try { at = new Attendance().Find(emp.EmployeeID, DateTime.Now, recursive: false, byPrimary: false); } catch (Exception e) { at.Absent = 0; at.Late = 0; at.Leave = emp.GetNumLeaves(DateTime.Now); at.Overtime = 0; at.Present = 0; at.Undertime = 0; at.Date = DateTime.Now; at.Employee = emp; if (String.IsNullOrEmpty(form.GetValue("v").AttemptedValue)) { throw new Exception("Form is incomplete"); } at.TotalWorkingDays = Int32.Parse(form.GetValue("v").AttemptedValue); at.Create(); count++; } } json["message"] = "Successfully create Attendance rows for " + count + " employees"; } } catch (Exception e) { json["error"] = true; json["message"] = e.Message; } } else { json["error"] = true; json["message"] = "You are not authorized to continue"; } } else { json["error"] = true; json["message"] = "Form is incomplete"; } return(Content(json.ToString(), "application/json")); }
public ContentResult AddAttendance(FormCollection form) { // add new attendance row for an employee JObject json = new JObject(); json["error"] = false; json["message"] = ""; string[] keys = new string[] { "id", "v" }; if (this.HasValues(form, keys)) { if (!this.CheckLogin(AccountType.Applicant) && ((Employee)this.GetAccount().Profile).Department.Type == DepartmentType.HumanResources) { try { if (String.IsNullOrEmpty(form.GetValue("id").AttemptedValue)) { throw new Exception("Form is incomplete"); } Employee emp = new Employee(Int32.Parse(form.GetValue("id").AttemptedValue), true); Attendance at = new Attendance(); try { at = new Attendance().Find(emp.EmployeeID, DateTime.Now, recursive: false, byPrimary: false); } catch (Exception e) { at.Absent = 0; at.Late = 0; at.Overtime = 0; at.Present = 0; at.Undertime = 0; at.Date = DateTime.Now; at.Employee = emp; at.Leave = emp.GetNumLeaves(DateTime.Now); if (String.IsNullOrEmpty(form.GetValue("v").AttemptedValue)) { throw new Exception("Form is incomplete"); } at.TotalWorkingDays = Int32.Parse(form.GetValue("v").AttemptedValue); at.Create(); json["message"] = "Successfully created Attendance row for: <b>" + emp.Profile.FirstName + " " + emp.Profile.LastName + "</b>"; } } catch (Exception e) { json["error"] = true; json["message"] = e.Message; } } else { json["error"] = true; json["message"] = "You are not authorized to continue"; } } else { json["error"] = true; json["message"] = "Form is incomplete"; } return(Content(json.ToString(), "application/json")); }