public async Task <IHttpActionResult> DeleteCourseType(ViewModels.CourseType dto) { var entity = await unitOfWork.CourseTypeRepository.GetByID(dto.Id); if (entity == null) { return(NotFound()); } var canDelete = unitOfWork.CourseTypeRepository.CanDelete(entity); if (canDelete.Code != HttpStatusCode.OK) { return(canDelete); } unitOfWork.CourseTypeRepository.Delete(entity); var saveResult = await unitOfWork.SaveAsync(); if (saveResult.Code != HttpStatusCode.OK) { return(saveResult); } return(Ok(dto)); }
public static void FillDto(Models.CourseType entity, ViewModels.CourseType coursetype) { coursetype.Id = entity.Id; coursetype.CalenderTypeId = entity.CalenderTypeId; coursetype.CourseCategoryId = entity.CourseCategoryId; coursetype.LicenseResultBasicId = entity.LicenseResultBasicId; coursetype.Title = entity.Title; coursetype.Remark = entity.Remark; coursetype.Interval = entity.Interval; coursetype.IsGeneral = entity.IsGeneral; coursetype.Status = entity.Status; }
public virtual CustomActionResult Validate(ViewModels.CourseType dto) { var c = dbSet.FirstOrDefault(q => q.Id != dto.Id && q.Title.ToLower().Trim() == dto.Title.ToLower().Trim()); if (c != null) { return(Exceptions.getDuplicateException("CourseType-01", "Title")); } return(new CustomActionResult(HttpStatusCode.OK, "")); }
public async Task <IHttpActionResult> PostCourseType(ViewModels.CourseType dto) { // return Ok(client); if (dto == null) { return(Exceptions.getNullException(ModelState)); } if (!ModelState.IsValid) { // return BadRequest(ModelState); return(Exceptions.getModelValidationException(ModelState)); } var validate = unitOfWork.CourseTypeRepository.Validate(dto); if (validate.Code != HttpStatusCode.OK) { return(validate); } CourseType entity = null; if (dto.Id == -1) { entity = new CourseType(); unitOfWork.CourseTypeRepository.Insert(entity); } else { entity = await unitOfWork.CourseTypeRepository.GetByID(dto.Id); } if (entity == null) { return(Exceptions.getNotFoundException()); } //ViewModels.Location.Fill(entity, dto); ViewModels.CourseType.Fill(entity, dto); var saveResult = await unitOfWork.SaveAsync(); if (saveResult.Code != HttpStatusCode.OK) { return(saveResult); } dto.Id = entity.Id; return(Ok(dto)); }