//missing entries public static List <MissingEntriesModel> GetMissingEntries(this UnitOfWork unit, int year, int month, ModelFactory factory) { List <MissingEntriesModel> missingEntriesList = new List <MissingEntriesModel>(); int days = DateTime.DaysInMonth(year, month); DateTime currentDate = new DateTime(year, month, days); var employees = unit.Employees.Get().Where(x => x.BeginDate <= currentDate && (x.EndDate == null || x.EndDate > currentDate)) .ToList(); foreach (var employee in employees) { List <int> workingDays = DateTimeHelper.ListOfWorkingDays(year, month, 1).ToList(); var employeeDays = employee.Days.Where(y => y.Date.Month == month && y.Date.Year == year) .Select(x => x.Date.Day).ToList(); var missing = workingDays.Except(employeeDays).ToList(); if (missing.Count() > 0) { EmployeeModel empl = new EmployeeModel() { FirstName = employee.FirstName, LastName = employee.LastName, Email = employee.Email }; MissingEntriesModel emp = new MissingEntriesModel() { Employee = empl, MissingDaysCount = Math.Abs(unit.Days.Get().Where(x => x.Employee.Id == employee.Id && x.Date.Year == year && x.Date.Month == month) .Count() - workingDays.Count()), MissingDays = missing, MailBody = "You are missing an entry" }; missingEntriesList.Add(emp); } } return(missingEntriesList); }
public IHttpActionResult Post([FromBody] MissingEntriesModel model) { var conString = "mongodb://localhost:27017"; var client = new MongoClient(conString); var DB = client.GetDatabase("Services"); var collection = DB.GetCollection <EmailEmployeeModel>("Emails"); //foreach (var employee in model.Employees) //{ // var document = new BsonDocument //{ // {"Name" , employee.Name }, // {"Email", employee.Email } //}; // var arr = new BsonArray(); // foreach (var entry in employee.MissingEntries) // { // arr.Add(new BsonDocument("Day:", entry.Day)); // } // document.Add("MissingEntries:", arr); // collection.InsertOne(document); //} foreach (var employee in model.Employees) { string MailToSend = "Dear " + employee.Name + " you have missing entries for Month : " + model.Month + " in Year: " + model.Year + " for days: "; EmailEmployeeModel employeeToAdd = new EmailEmployeeModel() { Name = employee.Name, Email = employee.Email, TotalMissingEntries = employee.MissingEntries.Count() }; foreach (var day in employee.MissingEntries) { MailToSend += day.Day + ", "; } employeeToAdd.MailToSend = MailToSend; collection.InsertOne(employeeToAdd); } return(Ok(model)); }
public IHttpActionResult Get(int year, int month) { MissingEntriesModel report = BuildReport(year, month); return(Ok(report)); }