Exemple #1
0
        public AttendanceAPIModel Map(AttendanceAPIShortModel attendanceModel)
        {
            if (attendanceModel == null)
            {
                return(null);
            }

            return(new AttendanceAPIModel
            {
                AttendanceStatus = attendanceModel.AttendanceStatus,
                Student = _iStudentAPIMapper.Map(_iStudentService.GetByUsername(attendanceModel.Username)),
                Laboratory = _iLaboratoryAPIMapper.Map(_iLaboratoryService.GetByLabNumber(attendanceModel.LabNumber))
            });
        }
        public HttpResponseMessage Update([FromBody] AttendanceAPIShortModel attendanceAPIShortModel)
        {
            if (attendanceAPIShortModel == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            var toUpdate = _attendanceService.GetByLabAndStud(attendanceAPIShortModel.LabNumber, attendanceAPIShortModel.Username);

            if (toUpdate.Id != 0)
            {
                _attendanceService.UpdateAttendance(new AttendanceModel {
                    Id = toUpdate.Id, AttendanceStatus = attendanceAPIShortModel.AttendanceStatus == "Present"
                });
                return(Request.CreateResponse(HttpStatusCode.Created, toUpdate.ToString()));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Attendance not added yet!"));
            }
        }
        public HttpResponseMessage Create([FromBody] AttendanceAPIShortModel attendanceAPIShortModel)
        {
            var attend = _attendanceService.GetByLabAndStud(attendanceAPIShortModel.LabNumber, attendanceAPIShortModel.Username);

            if (attend.Laboratory != null || attend.Student != null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Attendance already created!"));
            }

            else
            if (attendanceAPIShortModel == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            else
            {
                var att1 = _attendanceAPIShortModel.Map(attendanceAPIShortModel);
                var att  = _attendanceAPIMapper.Map(att1);
                _attendanceService.AddAttendance(att);
                return(Request.CreateResponse(HttpStatusCode.Created, _attendanceAPIMapper.Map(_attendanceAPIShortModel.Map(attendanceAPIShortModel))));
            }
        }