public async Task <JsonResult> SaveEvent(EmployeeEventViewModel e) { var status = false; IFormatProvider culture = new CultureInfo("en-US", true); EmployeeEvent eve = new EmployeeEvent() { CompanyID = CurrentCompanyId, Username = e.Username, Overtime = e.Overtime ?? 0, Start = DateTime.ParseExact(e.Start, "dd/MM/yyyy HH:mm tt", culture), End = DateTime.ParseExact(e.End, "dd/MM/yyyy HH:mm tt", culture), Description = e.Description ?? "No description", Color = e.Color, Status = StatusColor.MapColorToStatus(e.Color), IsFullDay = e.IsFullDay, EventID = e.EventID }; if (ModelState.IsValid) { status = await _employeeRepository.CreateEmployeeEventAsync(eve); } return(new JsonResult { Data = new { status = status } }); }
public IActionResult create([FromBody] EmployeeDTO employee) { try { // This needs to be checked against the partition assignment of response topic consumer // in future enhancements // This could affect response time var computePartition = _configuration.GetValue <bool>("ConfigProperties:Kafka:ComputePartition"); string requestId = _consumer.GenerateRequestId(computePartition); _logger.LogInformation("Computed request id using assigned partition from response topic {requestId}", requestId); // var reader = new StreamReader(Request.Body); _logger.LogInformation("Employee {firstname} {lastname} {middlename}", employee.FirstName, employee.LastName, employee.MiddleInitial); var value = new EmployeeEvent(); value.status = StatusType.REQUESTED; value.employee = _mapper.Map <Employee>(employee); value.employee.employeeID = requestId; //value.employee.nameFull = employee.nameFirst + employee.nameMiddle + employee.nameLast; value.action = ActionType.CREATE; _logger.LogInformation("Producing to {topicName}, key= {requestId}, value= {value}", topicName, requestId, value); _producer.ProduceRecord(topicName, requestId, value); EventWaitHandle syncObject = new AutoResetEvent(false); _synchronzationUtil.AddLockObject(requestId, syncObject); syncObject.WaitOne(); return(CreatedAtRoute("GetEmployeeById", new { id = _consumer.GetResponseById(requestId) })); } catch (Exception e) { _logger.LogError("Exception writing to kafka message {message}, stack trace {stack}", e.Message, e.StackTrace); return(this.StatusCode(StatusCodes.Status500InternalServerError, "Exception writing to kafka")); } }
public string GetDepartmentName() { if (EmployeeEvent != null) { EmployeeEvent.Invoke("GetDepartmentName()"); } return(DepartmentName); }
public int GetId() { if (EmployeeEvent != null) { EmployeeEvent.Invoke("GetId()"); } return(Id); }
/// <summary> /// The Following method is used to display all the usercontrol tabs /// in a list form using switch case that changes when the user click on a different /// usercontrol button. /// written by author : Abdelrahman Ahmed /// ref: https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.selectionchangedeventargs?view=netframework-4.7.2 /// using selection event changer with children to add new tab and clear the previous one. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) { UserControl tab = null; EventCenter.Children.Clear(); switch (((ListViewItem)((ListView)sender).SelectedItem).Name) { case "Dashboard": tab = new DashboardEvent(); EventCenter.Children.Add(tab); break; case "Storage": tab = new StorageEvent(); EventCenter.Children.Add(tab); break; case "Crops": tab = new CropsEvent(); EventCenter.Children.Add(tab); break; case "Delivery": tab = new DeliveryEvent(); EventCenter.Children.Add(tab); break; case "Timetable": tab = new TimetableEvent(); EventCenter.Children.Add(tab); break; case "Employees": tab = new EmployeeEvent(); EventCenter.Children.Add(tab); break; case "Schedule": tab = new ScheduleEvent(); EventCenter.Children.Add(tab); break; case "Sales": tab = new SalesEvent(); EventCenter.Children.Add(tab); break; case "Users": tab = new UserEvent(); EventCenter.Children.Add(tab); break; default: break; } }
/// <summary> /// Extension method to calculate working hour from an <see cref="EmployeeEvent"/> /// </summary> /// <param name="employeeEvent"></param> /// <returns></returns> internal static decimal CalculateWorkHours(this EmployeeEvent employeeEvent) { double startHour = employeeEvent.Start.Value.Hour != 0 ? employeeEvent.Start.Value.Hour : 24; double endHour = employeeEvent.End.Value.Hour != 0 ? employeeEvent.End.Value.Hour : 24; double startMinutes = employeeEvent.Start.Value.Minute; double endMinutes = employeeEvent.End.Value.Minute; return(startHour < endHour ? (decimal)(endHour - startHour - startMinutes + endMinutes) : (decimal)((24 - startHour) + endHour - startMinutes + endMinutes)); }
public async void ProduceRecord(string topicName, string key, EmployeeEvent value) { initProducer(); var Message = new Message <string, EmployeeEvent> { Key = key, Value = value }; DeliveryResult <string, EmployeeEvent> SentStatus = await _producer.ProduceAsync(topicName, Message); _logger.LogInformation("Produced message to topic '{Topic}', partition '{TopicPartition}' , Offset '{TopicPartitionOffset}'", SentStatus.Topic, SentStatus.TopicPartition.Partition.Value, SentStatus.TopicPartitionOffset.Offset); }
/// <summary> /// Creates or updates <see langword="async"/> an <see cref="EmployeeEvent"/> given the event and returns a result /// </summary> /// <param name="employeeEvent"></param> /// <returns><see cref="bool"/> succeeded</returns> public async Task <bool> CreateEmployeeEventAsync(EmployeeEvent employeeEvent) { var user = await GetEmployeeWithEventsAsync(employeeEvent.Username); var eve = user.EmployeeEvent.FirstOrDefault(e => e.EventID == employeeEvent.EventID); if (eve == null) { eve = new EmployeeEvent(); eve = employeeEvent; user.EmployeeEvent.Add(eve); _context.Events.AddOrUpdate(eve); return(await _context.SaveChangesAsync() > 0); } else { eve = employeeEvent; _context.Events.AddOrUpdate(eve); return(await _context.SaveChangesAsync() > 0); } }
public static void Initialize(ApplicationDbContext context) { context.Database.EnsureCreated(); string[] departmentsArray = new string[] { "Design", "Development", "Offshore", "Sales" }; Guid[] departmentsIds = new Guid[departmentsArray.Length]; string[] jobTitlesArray = new string[] { "Developer", "Architect", "Manager", "Designer" }; Guid[] jobTitlesIds = new Guid[jobTitlesArray.Length]; string[] statusArray = new string[] { "Work", "Sick", "Holliday", "Free" }; Guid[] statusesIds = new Guid[statusArray.Length]; Status[] statuses = new Status[statusArray.Length]; Employee[] employees = new Employee[65]; DateTime startDate = DateTime.UtcNow.AddDays(-60); #region Status if (!context.Status.Any()) { for (int i = 0; i < statuses.Length; i++) { statuses[i] = new Status { Id = Guid.NewGuid(), Title = statusArray[i] }; statusesIds[i] = statuses[i].Id; } context.AddRange(statuses); context.SaveChanges(); } #endregion #region Departments if (!context.Departments.Any()) { Department[] departments = new Department[departmentsArray.Length]; for (int i = 0; i < departments.Length; i++) { departments[i] = new Department { Id = Guid.NewGuid(), Title = departmentsArray[i] }; departmentsIds[i] = departments[i].Id; } context.AddRange(departments); context.SaveChanges(); } #endregion #region JobTitle if (!context.JobTitles.Any()) { JobTitle[] jobTitles = new JobTitle[jobTitlesArray.Length]; for (int i = 0; i < jobTitles.Length; i++) { jobTitles[i] = new JobTitle { Id = Guid.NewGuid(), Title = jobTitlesArray[i] }; jobTitlesIds[i] = jobTitles[i].Id; } context.AddRange(jobTitles); context.SaveChanges(); } #endregion #region Relations if (!context.Relations.Any()) { Relation[] relations = new Relation[15]; for (int i = 0; i < relations.Length; i++) { relations[i] = new Relation { Id = Guid.NewGuid(), RelationId = rnd.Next(1, 99999).ToString(), Title = Faker.Company.Name(), Address = new Address { Id = Guid.NewGuid(), Street = Faker.Address.StreetName(), House = rnd.Next(199).ToString(), City = Faker.Address.City(), Country = Faker.Address.Country(), PostCode = Faker.Address.ZipCode() }, Contact = new Contact { Id = Guid.NewGuid(), ContactPerson = Faker.Name.FullName(), PhoneNumber = Faker.Phone.Number(), Email = Faker.Internet.Email() }, Note = new Note { Id = Guid.NewGuid(), Title = Faker.Lorem.Sentence(2) } }; } context.AddRange(relations); context.SaveChanges(); } #endregion #region Employees if (!context.Employees.Any()) { var personGenerator = new PersonNameGenerator(); var relation = context.Relations.Where(x => x.RelationType == RelationType.Subcontractor).FirstOrDefault(); for (int i = 0; i < employees.Length; i++) { employees[i] = new Employee { Id = Guid.NewGuid(), EmployeeID = rnd.Next(1, 9999).ToString(), FirstName = personGenerator.GenerateRandomFirstName(), LastName = personGenerator.GenerateRandomLastName(), DepartmentId = departmentsIds[rnd.Next(4)], JobTitleId = jobTitlesIds[rnd.Next(4)], IsSubcontractor = false, //Subcontractor = relation, Address = new Address { Id = Guid.NewGuid(), Street = Faker.Address.StreetName(), House = rnd.Next(199).ToString(), Flat = rnd.Next(30).ToString(), City = Faker.Address.City(), Country = Faker.Address.Country(), PostCode = Faker.Address.ZipCode() }, Contact = new Contact { Id = Guid.NewGuid(), //ContactPerson = Faker.Name.FullName(), PhoneNumber = Faker.Phone.Number(), Email = Faker.Internet.Email() }, }; } context.AddRange(employees); context.SaveChanges(); } #endregion #region Cars if (!context.Cars.Any()) { Car[] cars = new Car[] { new Car { Id = Guid.NewGuid(), NumberPlate = "HHA015", Model = "Opel Astra" }, new Car { Id = Guid.NewGuid(), NumberPlate = "HHA012", Model = "Kia Ceed" }, new Car { Id = Guid.NewGuid(), NumberPlate = "OHB114", Model = "VW Gold" }, new Car { Id = Guid.NewGuid(), NumberPlate = "AHN336", Model = "Opel Vectra" } }; context.AddRange(cars); context.SaveChanges(); } #endregion #region Tags if (!context.Tags.Any()) { Tag[] tags = new Tag[] { new Tag { Id = Guid.NewGuid(), Title = "Java", Level = TagLevel.Level1, TagType = TagType.Employee }, new Tag { Id = Guid.NewGuid(), Title = "C#", Level = TagLevel.Level1, TagType = TagType.Employee }, new Tag { Id = Guid.NewGuid(), Title = "English", Level = TagLevel.Level2, TagType = TagType.Employee }, new Tag { Id = Guid.NewGuid(), Title = "Design", Level = TagLevel.Level3, TagType = TagType.Employee }, new Tag { Id = Guid.NewGuid(), Title = "Web", Level = TagLevel.Level1, TagType = TagType.Project }, new Tag { Id = Guid.NewGuid(), Title = "Mobile", Level = TagLevel.Level1, TagType = TagType.Project }, new Tag { Id = Guid.NewGuid(), Title = "India", Level = TagLevel.Level2, TagType = TagType.Project } }; context.AddRange(tags); context.SaveChanges(); } #endregion /* * // event generator * if (!context.Events.Any()) * { * List<Event> events = new List<Event>(); * * for (int i = 0; i < employees.Length; i++) * { * var amount = rnd.Next(10); * var date = startDate; * for (int j = 0; j < amount; j++) * { * var e = EventGenerator(employees[i].Id, date); * events.Add(e); * date = e.Till; * e = null; * } * } * context.AddRange(events); * context.SaveChanges(); * } */ #region Projects if (!context.Projects.Any()) { var client = context.Relations.FirstOrDefault(); Project[] project = new Project[] { new Project { Id = Guid.NewGuid(), Title = "GoBiGas", Manager = "Petras Kaufmanas", Client = client }, new Project { Id = Guid.NewGuid(), Title = "Piping installation", Manager = "Andris Parnu", Client = client }, new Project { Id = Guid.NewGuid(), Title = "Insulation Tanks", Manager = "Jeronimas Milius", Client = client }, }; context.AddRange(project); context.SaveChanges(); } #endregion #region Events if (!context.EmployeeEvents.Any()) { var employee = context.Employees.FirstOrDefault(); var project = context.Projects.FirstOrDefault(); EmployeeEvent[] employeeEvents = new EmployeeEvent[] { new EmployeeEvent { Id = Guid.NewGuid(), Start = DateTime.UtcNow.AddDays(-10), End = DateTime.UtcNow.AddDays(15), Resource = employee.Id, Project = project, Status = statuses[0] }, new EmployeeEvent { Id = Guid.NewGuid(), Start = DateTime.UtcNow.AddDays(25), End = DateTime.UtcNow.AddDays(120), Resource = employee.Id, Project = project, Status = statuses[1] } }; context.AddRange(employeeEvents); context.SaveChanges(); } if (!context.CarEvents.Any()) { var employee = context.Employees.FirstOrDefault(); var car = context.Cars.FirstOrDefault(); CarEvent[] carEvents = new CarEvent[] { new CarEvent { Id = Guid.NewGuid(), Start = DateTime.UtcNow.AddDays(-10), End = DateTime.UtcNow.AddDays(15), Resource = car.Id, Employee = employee, Status = statuses[2] }, new CarEvent { Id = Guid.NewGuid(), Start = DateTime.UtcNow.AddDays(25), End = DateTime.UtcNow.AddDays(120), Resource = car.Id, Employee = employee, Status = statuses[0] } }; context.AddRange(carEvents); context.SaveChanges(); } #endregion }
public EmployeeEventArgs(object data, EmployeeEvent employeeEvent) { EmployeeEvent = employeeEvent; Data = data; }