예제 #1
0
        public IHttpActionResult Put(int id, CreateOrUpdateStudentInputDTO student)
        {
            try
            {
                var studentInDb = _unitOfWork.Students.SingleOrDefault(c => c.studID == id);

                if (studentInDb == null)
                {
                    return(NotFound());
                }

                studentInDb.studName     = student.studName;
                studentInDb.ClassID      = student.ClassID;
                studentInDb.RollNo       = student.RollNo;
                studentInDb.studAddress1 = student.studAddress1;
                studentInDb.studAddress2 = student.studAddress2;
                studentInDb.studAddress3 = student.studAddress3;
                studentInDb.studlZip     = student.studlZip;
                studentInDb.schlMailID   = student.schlMailID;
                studentInDb.studMobileNo = student.studMobileNo;
                studentInDb.schlMailID   = student.schlMailID;
                studentInDb.ModifyBy     = student.ModifyBy;
                studentInDb.ModifyDate   = DateTime.UtcNow;
                _unitOfWork.Students.Update(studentInDb);
                Mapper.CreateMap <Student, StudentListDTO>();
                return(Ok(Mapper.Map <Student, StudentListDTO>(studentInDb)));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
예제 #2
0
 public IHttpActionResult Post(CreateOrUpdateStudentInputDTO studentDto)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest());
         }
         Mapper.CreateMap <CreateOrUpdateStudentInputDTO, Student>().ForMember(m => m.studID, opt => opt.Ignore());
         var student = Mapper.Map <CreateOrUpdateStudentInputDTO, Student>(studentDto);
         _unitOfWork.Students.Add(student);
         _unitOfWork.Complete();
         return(Created(new Uri(Request.RequestUri + "/" + student.studID), student));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }