public static int Create(CourseDataModel data, RequestProfile requestProfile) { var sql = Save(data, "Create", requestProfile); var newId = DBDML.RunScalarSQL("Course.Insert", sql, DataStoreKey); return(Convert.ToInt32(newId)); }
public static string Save(CourseDataModel data, string action, RequestProfile requestProfile) { var sql = "EXEC "; switch (action) { case "Create": sql += "dbo.CourseInsert " + " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId) + ", " + ToSQLParameter(BaseDataModel.BaseDataColumns.ApplicationId, requestProfile.ApplicationId); break; case "Update": sql += "dbo.CourseUpdate " + " " + ToSQLParameter(BaseDataModel.BaseDataColumns.AuditId, requestProfile.AuditId); break; default: break; } sql = sql + ", " + ToSQLParameter(data, CourseDataModel.DataColumns.CourseId); sql = sql + ", " + ToSQLParameter(data, CourseDataModel.DataColumns.Name); sql = sql + ", " + ToSQLParameter(data, CourseDataModel.DataColumns.Description); sql = sql + ", " + ToSQLParameter(data, CourseDataModel.DataColumns.Duration); sql = sql + ", " + ToSQLParameter(data, CourseDataModel.DataColumns.Fees); sql = sql + ", " + ToSQLParameter(data, CourseDataModel.DataColumns.SortOrder); return(sql); }
public IHttpActionResult DeleteCourse(CourseDataModel course) { MemberDataModel member = this.GetUser(); ApiResult apiResult = new ApiResult(); if (member != null && MemberService.IsAdmin(member)) { apiResult.Data = this.CourseService.DeleteCourse(course.CourseSerilNo); apiResult.Status = Models.Enum.ApiStatus.Success; apiResult.Message = "刪除成功"; } else { apiResult.Status = Models.Enum.ApiStatus.Fail; apiResult.Message = "不要亂改"; } return(Ok(apiResult)); //ApiResult apiResult = new ApiResult(); //apiResult.Data = this.CourseService.DeleteCourse(course.CourseSerilNo); //apiResult.Status = Models.Enum.ApiStatus.Success; //apiResult.Message = "刪除成功"; //return Ok(apiResult); }
public void Delete(string value) { var dataQuery = new CourseDataModel(); dataQuery.CourseId = int.Parse(value); CourseDataManager.Delete(dataQuery, SessionVariables.RequestProfile); }
public CourseDataModel GetById(string value) { var dataQuery = new CourseDataModel(); dataQuery.CourseId = int.Parse(value); var result = CourseDataManager.GetEntityDetails(dataQuery, SessionVariables.RequestProfile, 1); return(result[0]); }
public static bool DoesExist(CourseDataModel data, RequestProfile requestProfile) { var doesExistRequest = new CourseDataModel(); doesExistRequest.ApplicationId = data.ApplicationId; var list = GetEntityDetails(doesExistRequest, requestProfile, 0); return(list.Count > 0); }
public IHttpActionResult Post([FromBody] CourseDataModel courseModel) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } var course = CourseDataModel.FromModelToData(courseModel); this.Data.Courses.Add(course); this.Data.SaveChanges(); return(this.Created(this.Url.ToString(), course)); }
public static void Delete(CourseDataModel data, RequestProfile requestProfile) { const string sql = @"dbo.CourseDelete "; var parameters = new { AuditId = requestProfile.AuditId , CourseId = data.CourseId }; using (var dataAccess = new DataAccessBase(DataStoreKey)) { dataAccess.Connection.Execute(sql, parameters, commandType: CommandType.StoredProcedure); } }
public static List <CourseDataModel> GetEntityDetails(CourseDataModel dataQuery, RequestProfile requestProfile, int returnAuditInfo = BaseDataManager.ReturnAuditInfoOnDetails) { const string sql = @"dbo.CourseSearch "; var parameters = new { AuditId = requestProfile.AuditId , ApplicationId = requestProfile.ApplicationId , ReturnAuditInfo = returnAuditInfo , CourseId = dataQuery.CourseId }; List <CourseDataModel> result; using (var dataAccess = new DataAccessBase(DataStoreKey)) { result = dataAccess.Connection.Query <CourseDataModel>(sql, parameters, commandType: CommandType.StoredProcedure).ToList(); } return(result); }
public IHttpActionResult Put(string id, [FromBody] CourseDataModel courseModel) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } var course = this.Data.Courses.SearchFor(c => c.Id.ToString() == id).FirstOrDefault(); if (course == null) { return(this.BadRequest("Invalid id")); } course.Description = string.IsNullOrEmpty(courseModel.Description) ? course.Description : courseModel.Description; course.Name = string.IsNullOrEmpty(courseModel.Name) ? course.Name : courseModel.Name; this.Data.Courses.Update(course); this.Data.SaveChanges(); return(this.Ok()); }
public List <CourseDataModel> CreateCourse(CourseDataModel newCourse) { string sql = @"EXEC sp_create_course @CourseName, @CategoryCode, @Desc, @CreateUser, @Price, @CourseImageName, @TtlHr, @LearningText, @RequirementText, @InsText, @TargetText, @ShortIntroText, @TeacherPerSerilNo"; object parameters = new { CourseName = newCourse.CourseName, CategoryCode = newCourse.CategoryCode, Desc = newCourse.Description, CreateUser = "******", Price = newCourse.Price, CourseImageName = newCourse.CourseImageName, TtlHr = newCourse.TtlHr, LearningText = newCourse.LearningText, RequirementText = newCourse.RequirementText, InsText = newCourse.InsText, TargetText = newCourse.TargetText, ShortIntroText = newCourse.ShortIntroText, TeacherPerSerilNo = newCourse.TeacherPerSerilNo }; using (var connection = new SqlConnection(this.GetDbConnectionString())) { List <CourseDataModel> result = connection.Query <CourseDataModel>(sql, parameters).ToList(); return(result); } }
public IHttpActionResult CreateCourse(CourseDataModel newCourse) { MemberDataModel member = this.GetUser(); ApiResult apiResult = new ApiResult(); if (member != null && MemberService.IsAdmin(member)) { apiResult.Data = CourseService.CreateCourse(newCourse); apiResult.Status = Models.Enum.ApiStatus.Success; apiResult.Message = "新增成功"; } else { apiResult.Status = Models.Enum.ApiStatus.Fail; apiResult.Message = "不要亂改"; } return(Ok(apiResult)); //ApiResult result = new ApiResult(); //result.Data = CourseService.CreateCourse(newCourse); //return Ok(result); }
public List <CourseDataModel> CreateCourse(CourseDataModel newCourse) { return(this.CourseDao.CreateCourse(newCourse)); }
public void Update([FromBody] CourseDataModel data) { CourseDataManager.Update(data, SessionVariables.RequestProfile); }
public static void Update(CourseDataModel data, RequestProfile requestProfile) { var sql = Save(data, "Update", requestProfile); DBDML.RunSQL("Course.Update", sql, DataStoreKey); }
public static string ToSQLParameter(CourseDataModel data, string dataColumnName) { var returnValue = "NULL"; switch (dataColumnName) { case CourseDataModel.DataColumns.CourseId: if (data.CourseId != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CourseDataModel.DataColumns.CourseId, data.CourseId); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CourseDataModel.DataColumns.CourseId); } break; case CourseDataModel.DataColumns.Name: if (!string.IsNullOrEmpty(data.Name)) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, CourseDataModel.DataColumns.Name, data.Name); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CourseDataModel.DataColumns.Name); } break; case CourseDataModel.DataColumns.Description: if (!string.IsNullOrEmpty(data.Description)) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_STRING_OR_DATE, CourseDataModel.DataColumns.Description, data.Description); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CourseDataModel.DataColumns.Description); } break; case CourseDataModel.DataColumns.Duration: if (data.Duration != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CourseDataModel.DataColumns.Duration, data.Duration); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CourseDataModel.DataColumns.Duration); } break; case CourseDataModel.DataColumns.Fees: if (data.Fees != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CourseDataModel.DataColumns.Fees, data.Fees); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CourseDataModel.DataColumns.Fees); } break; case CourseDataModel.DataColumns.SortOrder: if (data.SortOrder != null) { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NUMBER, CourseDataModel.DataColumns.SortOrder, data.SortOrder); } else { returnValue = string.Format(SQL_TEMPLATE_PARAMETER_NULL, CourseDataModel.DataColumns.SortOrder); } break; default: returnValue = BaseDataManager.ToSQLParameter(data, dataColumnName); break; } return(returnValue); }
public List <CourseDataModel> UpdateCourse(CourseDataModel course) { return(this.CourseDao.UpdateCourse(course)); }
public static DataTable Search(CourseDataModel data, RequestProfile requestProfile) { var list = GetEntityDetails(data, requestProfile, 0); return(list.ToDataTable()); }