public IHttpActionResult Put(int id, CreateOrUpdateSchoolInputDTO school) { try { var schoolInDb = _unitOfWork.Schools.SingleOrDefault(c => c.schlID == id); if (schoolInDb == null) { return(NotFound()); } schoolInDb.schoolName = school.schoolName; schoolInDb.cityId = school.CityID; schoolInDb.schlAddress1 = school.schlAddress1; schoolInDb.schlAddress2 = school.schlAddress2; schoolInDb.schlAddress3 = school.schlAddress3; schoolInDb.schlLatitude = school.schlLatitude; schoolInDb.schlLongitude = school.schlLongitude; schoolInDb.schlMailID = school.schlMailID; schoolInDb.schlMobileNo = school.schlMobileNo; schoolInDb.schlPOCName = school.schlPOCName; schoolInDb.schlTeleNo = school.schlTeleNo; schoolInDb.schlZip = school.schlZip; schoolInDb.ModifyDate = DateTime.UtcNow; _unitOfWork.Schools.Update(schoolInDb); Mapper.CreateMap <School, SchoolListDTO>(); return(Ok(Mapper.Map <School, SchoolListDTO>(schoolInDb))); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult Post(CreateOrUpdateSchoolInputDTO input) { try { if (!ModelState.IsValid) { return(BadRequest()); } Mapper.CreateMap <CreateOrUpdateSchoolInputDTO, School>().ForMember(m => m.schlID, opt => opt.Ignore()); var school = Mapper.Map <CreateOrUpdateSchoolInputDTO, School>(input); _unitOfWork.Schools.Add(school); _unitOfWork.Complete(); return(Created(new Uri(Request.RequestUri + "/" + school.schlID), school)); } catch (Exception ex) { return(InternalServerError(ex)); } }