Esempio n. 1
0
        public HttpResponseMessage Update([FromBody] StudentAPIModel studentAPIModel)
        {
            if (studentAPIModel == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            if (_iStudentService.CheckIsStudentExists(studentAPIModel.Username) == true)
            {
                _iStudentService.UpdateStudent(_iStudentAPIMapper.Map(studentAPIModel));
                return(Request.CreateResponse(HttpStatusCode.Created, _iStudentAPIMapper.Map(studentAPIModel)));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Student is not enrolled in this class!"));
            }
        }
Esempio n. 2
0
        public HttpResponseMessage Create([FromBody] StudentAPIModel studentAPIModel)
        {
            if (_iStudentService.GetByUsername(_iStudentAPIMapper.Map(studentAPIModel).Username) != null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Username already used!"));
            }

            else
            if (studentAPIModel == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            else
            {
                _iStudentService.AddStudent(_iStudentAPIMapper.Map(studentAPIModel));
                return(Request.CreateResponse(HttpStatusCode.Created, _iStudentAPIMapper.Map(studentAPIModel)));
            }
        }
Esempio n. 3
0
        public StudentModel Map(StudentAPIModel studentAPIModel)
        {
            if (studentAPIModel == null)
            {
                return(null);
            }

            return(new StudentModel
            {
                Token = studentAPIModel.Token,
                Username = studentAPIModel.Username,
                EncPassword = studentAPIModel.EncPassword,
                Name = studentAPIModel.Name,
                Email = studentAPIModel.Email,
                GroupNo = studentAPIModel.GroupNo,
                Hobby = studentAPIModel.Hobby
            });
        }