Beispiel #1
0
        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));
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        public void Delete(string value)
        {
            var dataQuery = new CourseDataModel();

            dataQuery.CourseId = int.Parse(value);
            CourseDataManager.Delete(dataQuery, SessionVariables.RequestProfile);
        }
Beispiel #5
0
        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]);
        }
Beispiel #6
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));
        }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
        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());
        }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
 public List <CourseDataModel> CreateCourse(CourseDataModel newCourse)
 {
     return(this.CourseDao.CreateCourse(newCourse));
 }
Beispiel #14
0
 public void Update([FromBody] CourseDataModel data)
 {
     CourseDataManager.Update(data, SessionVariables.RequestProfile);
 }
Beispiel #15
0
        public static void Update(CourseDataModel data, RequestProfile requestProfile)
        {
            var sql = Save(data, "Update", requestProfile);

            DBDML.RunSQL("Course.Update", sql, DataStoreKey);
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
 public List <CourseDataModel> UpdateCourse(CourseDataModel course)
 {
     return(this.CourseDao.UpdateCourse(course));
 }
Beispiel #18
0
        public static DataTable Search(CourseDataModel data, RequestProfile requestProfile)
        {
            var list = GetEntityDetails(data, requestProfile, 0);

            return(list.ToDataTable());
        }