public JsonReturnModel getAttendence(StudentAttendence StudentAttendence) { List <AttendenceModel> attendenceList = new List <AttendenceModel>(); var Customer = _CustomerService.GetCustomer(StudentAttendence.CustomerId).CustomerType; if (Customer != null) { if (Customer == StudentAttendence.CustomerType) { if (Customer == EnumValue.GetEnumDescription(EnumValue.CustomerType.Student) || Customer == EnumValue.GetEnumDescription(EnumValue.CustomerType.Parent)) { var attendences = _AttendenceService.GetAttendences().Where(a => (a.AttendenceDate >= StudentAttendence.StartDate && a.AttendenceDate <= StudentAttendence.EndDate) && a.CustomerId == StudentAttendence.CustomerId).ToList(); if (attendences.Count() > 0) { foreach (var item in attendences) { if (item.Status == EnumValue.GetEnumDescription(EnumValue.AttendenceStatus.Present)) { Mapper.CreateMap <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>(); Onlo.Models.AttendenceModel Attendence = Mapper.Map <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>(item); attendenceList.Add(Attendence); } } } } else { var CustomerList = _CustomerService.GetCustomers().Where(c => c.ParentId == StudentAttendence.CustomerId).ToList(); if (CustomerList.Count() > 0) { var CustomerIds = CustomerList.Select(s => s.CustomerId).ToList(); foreach (var CustomerId in CustomerIds) { var studentAttendence = _AttendenceService.GetAttendences().Where(a => a.CustomerId == CustomerId && a.AttendenceDate == StudentAttendence.StartDate).FirstOrDefault(); if (studentAttendence != null) { Mapper.CreateMap <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>(); Onlo.Models.AttendenceModel Attendence = Mapper.Map <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>(studentAttendence); var studentDetail = _CustomerService.GetCustomer(studentAttendence.CustomerId); Attendence.StudentName = studentDetail.Name; Attendence.StudentCode = studentDetail.StudentCode; Attendence.ProfilePath = studentDetail.PhotoPath; Attendence.EmailId = studentDetail.EmailId; attendenceList.Add(Attendence); } } } } return(CommonCls.CreateMessage("success", attendenceList)); } else { return(CommonCls.CreateMessage("error", "This Customer doesnot exist in this customer type.")); } } else { return(CommonCls.CreateMessage("success", "No attendence found.")); } }
public HttpResponseMessage GetAttendenceSummary([FromUri] int CustomerId) { try { if (CustomerId == 0) { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank."), Configuration.Formatters.JsonFormatter)); } var attendences = _AttendenceService.GetAttendences().Where(a => a.CustomerId == CustomerId).ToList(); if (attendences.Count() > 0) { var models = new List <AttendenceModel>(); Mapper.CreateMap <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>(); foreach (var attendence in attendences) { Onlo.Models.AttendenceModel Attendence = Mapper.Map <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>(attendence); models.Add(Attendence); } return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", models), Configuration.Formatters.JsonFormatter)); } else { return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "No attendence 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)); } }