public async Task <IActionResult> AtteRequest(AttendenceModel attendenceModel) { string user = User.FindFirst("Index").Value; var Currentuser = await _taskRepository.GetCurrentUser(user); ViewBag.photo = Currentuser.PhotoURL; int EmpId = Currentuser.EmpId; attendenceModel.EmpId = Currentuser.EmpId; bool existOne = _attendenceRepo.CheckExist(attendenceModel.EmpId, attendenceModel.Date); if (existOne) { return(RedirectToAction(nameof(AtteRequest), new { isExist = true })); } else { TimeSpan differ = (TimeSpan)(attendenceModel.OutTime - attendenceModel.InTime); attendenceModel.TotalHours = differ.TotalHours; double breakTime = ((attendenceModel.BHours * 60.0) + attendenceModel.BMinutes) / 60.0; attendenceModel.BreakingHours = breakTime; attendenceModel.WorkingHours = differ.TotalHours - breakTime; int id = await _attendenceRepo.AddRequest(attendenceModel); if (id > 0) { return(RedirectToAction(nameof(AtteRequest), new { isSucceess = true })); } } return(View()); }
public void UpdateAttendences(List <AttendenceViewModel> attendences) { var modelsAttendences = new List <AttendenceModel>(); foreach (var attendence in attendences) { var deltagare = deltagareDb.GetAllDeltagarModels().First(x => x.DeltagarNamn == attendence.DeltagarNamn); var model = new AttendenceModel { DateConcerning = attendence.DateConcerning, DeltagarIdInQuestion = deltagare.Id, Måndag = attendence.Måndag.ToString(), Tisdag = attendence.Tisdag.ToString(), Onsdag = attendence.Onsdag.ToString(), Torsdag = attendence.Torsdag.ToString(), Fredag = attendence.Fredag.ToString(), ExpectedMåndag = attendence.ExpectedMåndag.ToString(), ExpectedTisdag = attendence.ExpectedTisdag.ToString(), ExpectedOnsdag = attendence.ExpectedOnsdag.ToString(), ExpectedTorsdag = attendence.ExpectedTorsdag.ToString(), ExpectedFredag = attendence.ExpectedFredag.ToString(), Id = attendence.Id, }; modelsAttendences.Add(model); } foreach (var model in modelsAttendences) { närvaroDb.UpdateAttendence(model); } }
public void UpdateAttendence(AttendenceModel model) { UpdateProperty("Måndag", model.Id, model.Måndag.ToString()); UpdateProperty("Tisdag", model.Id, model.Tisdag.ToString()); UpdateProperty("Onsdag", model.Id, model.Onsdag.ToString()); UpdateProperty("Torsdag", model.Id, model.Torsdag.ToString()); UpdateProperty("Fredag", model.Id, model.Fredag.ToString()); }
public void a3TestAddAttendence() { var deltagare = deltagareDb.GetAllDeltagarModels().FirstOrDefault(x => x.DeltagarNamn == deltagarNamn); var attendenceModel = new AttendenceModel { DateConcerning = DateTime.Now, DeltagarIdInQuestion = deltagare.Id, ExpectedMåndag = deltagare.Måndag, ExpectedTisdag = deltagare.Tisdag, ExpectedOnsdag = deltagare.Onsdag, ExpectedTorsdag = deltagare.Torsdag, ExpectedFredag = deltagare.Fredag, Måndag = AttendenceOption.HalvdagMat.ToString(), Tisdag = AttendenceOption.Heldag.ToString(), Onsdag = AttendenceOption.Heldag.ToString(), Torsdag = AttendenceOption.Heldag.ToString(), Fredag = AttendenceOption.Halvdag.ToString() }; närvaroDb.AddAttendence(attendenceModel); Assert.AreEqual(AttendenceOption.HalvdagMat.ToString(), närvaroDb.GetAllAttendenceItems().FirstOrDefault(x => x.DeltagarIdInQuestion == deltagare.Id).Måndag); }
public async Task <AttendenceModel> GetWorkLog(int id) { AttendenceModel am = new AttendenceModel(); var info = _context.TimeTracker.SingleOrDefault(x => (x.EmpId == id) && (x.Date == DateTime.Now.Date)); if (info.Status == "Work") { am.InTime = (DateTime)info.InTime; am.Status = info.Status; return(am); } else { am.InTime = (DateTime)info.InTime; am.OutTime = (DateTime)info.OutTime; am.TotalHours = info.TotalHours; am.Status = info.Status; return(am); } }
public void AddNärvaro(AttendenceViewModel viewModel) { var deltagare = deltagareDb.GetAllDeltagarModels().First(x => x.DeltagarNamn == viewModel.DeltagarNamn); var model = new AttendenceModel { DateConcerning = viewModel.DateConcerning, DeltagarIdInQuestion = deltagare.Id, Måndag = viewModel.Måndag.ToString(), Tisdag = viewModel.Tisdag.ToString(), Onsdag = viewModel.Onsdag.ToString(), Torsdag = viewModel.Torsdag.ToString(), Fredag = viewModel.Fredag.ToString(), ExpectedMåndag = deltagare.Måndag, ExpectedTisdag = deltagare.Tisdag, ExpectedOnsdag = deltagare.Onsdag, ExpectedTorsdag = deltagare.Torsdag, ExpectedFredag = deltagare.Fredag }; närvaroDb.AddAttendence(model); }
public void UpdateAttendence(AttendenceViewModel attendence) { var deltagare = deltagareDb.GetAllDeltagarModels().First(x => x.DeltagarNamn == attendence.DeltagarNamn); var model = new AttendenceModel { DateConcerning = attendence.DateConcerning, DeltagarIdInQuestion = deltagare.Id, Måndag = attendence.Måndag.ToString(), Tisdag = attendence.Tisdag.ToString(), Onsdag = attendence.Onsdag.ToString(), Torsdag = attendence.Torsdag.ToString(), Fredag = attendence.Fredag.ToString(), ExpectedMåndag = attendence.ExpectedMåndag.ToString(), ExpectedTisdag = attendence.ExpectedTisdag.ToString(), ExpectedOnsdag = attendence.ExpectedOnsdag.ToString(), ExpectedTorsdag = attendence.ExpectedTorsdag.ToString(), ExpectedFredag = attendence.ExpectedFredag.ToString(), Id = attendence.Id, }; närvaroDb.UpdateAttendence(model); }
public async Task <int> AddRequest(AttendenceModel attendenceModel) { var attendence = new Attendence() { Date = attendenceModel.Date, InTime = attendenceModel.InTime, OutTime = attendenceModel.OutTime, TotalHours = attendenceModel.TotalHours, BreakingHours = attendenceModel.BreakingHours, WorkingHours = attendenceModel.WorkingHours, Explanation = attendenceModel.Explanation, EmpId = attendenceModel.EmpId, Type = "Manual", AppliedDate = DateTime.UtcNow, Status = "Pending" }; await _context.Attendence.AddAsync(attendence); await _context.SaveChangesAsync(); return(attendence.AttendenceId); }
public HttpResponseMessage SaveAttendence([FromBody] AttendenceModel AttendenceModel) { try { List <Attendence> model = new List <Attendence>(); if (AttendenceModel.AbsentCustomerIds == null && AttendenceModel.AbsentCustomerIds == "" || AttendenceModel.PresentCustomerIds == null && AttendenceModel.PresentCustomerIds == "") { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Absent or PresentCustomer Ids is blank."), Configuration.Formatters.JsonFormatter)); } if (AttendenceModel.AttendenceDate == null) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Attendence Date is blank."), Configuration.Formatters.JsonFormatter)); } var customerTeacher = _CustomerService.GetCustomer(AttendenceModel.TeacherId); if (customerTeacher == null) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No teacher found."), Configuration.Formatters.JsonFormatter)); } var CustomerList = _CustomerService.GetCustomers().Where(c => c.ParentId == AttendenceModel.TeacherId).ToList(); if (CustomerList.Count() > 0) { var CustomerIds = CustomerList.Select(s => s.CustomerId).ToList(); if (AttendenceModel.PresentCustomerIds != null && AttendenceModel.PresentCustomerIds != "") { var PresentCustomerIds = AttendenceModel.PresentCustomerIds.Split(','); var PresentIds = PresentCustomerIds.Select(int.Parse).ToList(); foreach (var item in PresentIds) { var attendenceFound = _AttendenceService.GetAttendences().Where(t => t.AttendenceDate == AttendenceModel.AttendenceDate && t.CustomerId == item && t.TeacherId == AttendenceModel.TeacherId).FirstOrDefault(); if (attendenceFound == null) { Mapper.CreateMap <Onlo.Models.AttendenceModel, Onlo.Entity.Attendence>(); Onlo.Entity.Attendence Attendence = Mapper.Map <Onlo.Models.AttendenceModel, Onlo.Entity.Attendence>(AttendenceModel); Attendence.Status = EnumValue.GetEnumDescription(EnumValue.AttendenceStatus.Present); Attendence.CustomerId = item; _AttendenceService.InsertAttendence(Attendence); model.Add(Attendence); } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Attendence already marked."), Configuration.Formatters.JsonFormatter)); } } } if (AttendenceModel.AbsentCustomerIds != null && AttendenceModel.AbsentCustomerIds != "") { var AbsentCustomerIds = AttendenceModel.AbsentCustomerIds.Split(','); var AbsentIds = AbsentCustomerIds.Select(int.Parse).ToList(); if (AbsentIds.Count() > 0) { foreach (var item in AbsentIds) { var attendenceFound = _AttendenceService.GetAttendences().Where(t => t.AttendenceDate == AttendenceModel.AttendenceDate && t.CustomerId == item && t.TeacherId == AttendenceModel.TeacherId).FirstOrDefault(); if (attendenceFound == null) { Mapper.CreateMap <Onlo.Models.AttendenceModel, Onlo.Entity.Attendence>(); Onlo.Entity.Attendence Attendence = Mapper.Map <Onlo.Models.AttendenceModel, Onlo.Entity.Attendence>(AttendenceModel); Attendence.Status = EnumValue.GetEnumDescription(EnumValue.AttendenceStatus.Absent); Attendence.CustomerId = item; _AttendenceService.InsertAttendence(Attendence); model.Add(Attendence); } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Attendence already marked."), Configuration.Formatters.JsonFormatter)); } } } } return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", model), Configuration.Formatters.JsonFormatter)); } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No teacher found."), Configuration.Formatters.JsonFormatter)); } } catch (Exception ex) { string ErrorMsg = ex.Message.ToString(); ErrorLogging.LogError(ex); return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "please try again."), Configuration.Formatters.JsonFormatter)); } }
public List <AttendenceViewModel> GetAttendenceForDate(DateTime date, DeltagareViewModel deltagarModel) { if (date.DayOfWeek == DayOfWeek.Tuesday) { date = date.AddDays(-1); } else if (date.DayOfWeek == DayOfWeek.Wednesday) { date = date.AddDays(-2); } else if (date.DayOfWeek == DayOfWeek.Thursday) { date = date.AddDays(-3); } else if (date.DayOfWeek == DayOfWeek.Friday) { date = date.AddDays(-4); } else if (date.DayOfWeek == DayOfWeek.Saturday) { date = date.AddDays(-5); } else if (date.DayOfWeek == DayOfWeek.Sunday) { date = date.AddDays(-6); } var returningList = new List <AttendenceViewModel>(); var deltagarnaActive = deltagareDb.GetAllDeltagarModels().Where(x => x.DeltagarNamn == deltagarModel.DeltagarNamn).ToList(); foreach (var deltagare in deltagarnaActive) { var attendences = närvaroDb.GetAttendenceForDate(date).Where(x => x.DeltagarIdInQuestion == deltagare.Id).ToList(); if (attendences.Count == 0) { var model = new AttendenceModel { DateConcerning = date, DeltagarIdInQuestion = deltagare.Id, ExpectedFredag = deltagare.Fredag, ExpectedTorsdag = deltagare.Torsdag, ExpectedOnsdag = deltagare.Onsdag, ExpectedTisdag = deltagare.Tisdag, ExpectedMåndag = deltagare.Måndag, Fredag = AttendenceOption.Frånvarande.ToString(), Torsdag = AttendenceOption.Frånvarande.ToString(), Onsdag = AttendenceOption.Frånvarande.ToString(), Tisdag = AttendenceOption.Frånvarande.ToString(), Måndag = AttendenceOption.Frånvarande.ToString() }; närvaroDb.AddAttendence(model); model = närvaroDb.GetAttendenceForDate(date).LastOrDefault(x => x.DeltagarIdInQuestion == deltagare.Id); var viewModel = new AttendenceViewModel { DateConcerning = date, DeltagarIdInQuestion = deltagare.Id, DeltagarNamn = deltagareDb.GetDeltagare(model.DeltagarIdInQuestion).DeltagarNamn, ExpectedFredag = HelperConvertLogic.GetWorkDayFromString(deltagare.Fredag), ExpectedTorsdag = HelperConvertLogic.GetWorkDayFromString(deltagare.Torsdag), ExpectedOnsdag = HelperConvertLogic.GetWorkDayFromString(deltagare.Onsdag), ExpectedTisdag = HelperConvertLogic.GetWorkDayFromString(deltagare.Tisdag), ExpectedMåndag = HelperConvertLogic.GetWorkDayFromString(deltagare.Måndag), Fredag = AttendenceOption.Frånvarande, Torsdag = AttendenceOption.Frånvarande, Onsdag = AttendenceOption.Frånvarande, Tisdag = AttendenceOption.Frånvarande, Måndag = AttendenceOption.Frånvarande, Id = model.Id }; returningList.Add(viewModel); } else { var model = attendences.FirstOrDefault(x => x.DeltagarIdInQuestion == deltagare.Id); var viewModel = new AttendenceViewModel { Id = model.Id, DateConcerning = date, DeltagarIdInQuestion = deltagare.Id, DeltagarNamn = deltagareDb.GetDeltagare(model.DeltagarIdInQuestion).DeltagarNamn, ExpectedFredag = HelperConvertLogic.GetWorkDayFromString(deltagare.Fredag), ExpectedTorsdag = HelperConvertLogic.GetWorkDayFromString(deltagare.Torsdag), ExpectedOnsdag = HelperConvertLogic.GetWorkDayFromString(deltagare.Onsdag), ExpectedTisdag = HelperConvertLogic.GetWorkDayFromString(deltagare.Tisdag), ExpectedMåndag = HelperConvertLogic.GetWorkDayFromString(deltagare.Måndag), Fredag = HelperConvertLogic.GetAttendenceOptionFromString(model.Fredag), Torsdag = HelperConvertLogic.GetAttendenceOptionFromString(model.Torsdag), Onsdag = HelperConvertLogic.GetAttendenceOptionFromString(model.Onsdag), Tisdag = HelperConvertLogic.GetAttendenceOptionFromString(model.Tisdag), Måndag = HelperConvertLogic.GetAttendenceOptionFromString(model.Måndag) }; returningList.Add(viewModel); } } return(returningList); }
public void AddAttendence(AttendenceModel model) { närvarodb.InsertOne(model); }