コード例 #1
0
        public Response <StudentModel> CreateStudent(StudentCreateRequestModel model)
        {
            try
            {
                using (var unitOfWork = new UnitOfWork())
                {
                    var db = unitOfWork.DataContext;

                    var newStudent = new cms_Student();

                    newStudent.Name     = model.Name;
                    newStudent.Phone    = model.Phone;
                    newStudent.Address  = model.Address;
                    newStudent.Email    = model.Email;
                    newStudent.ClassId  = model.ClassId;
                    newStudent.Facebook = model.Facebook;
                    newStudent.GroupId  = model.GroupId;
                    db.cms_Student.Add(newStudent);
                    var commitResult = unitOfWork.Save();
                    if (commitResult >= ConfigType.SUCCESS)
                    {
                        return(new Response <StudentModel>(ConfigType.SUCCESS, "Ok", ConvertStudent(newStudent)));
                    }
                    else
                    {
                        return(new Response <StudentModel>(ConfigType.NODATA, "NOT OK", null));
                    }
                }
            }catch (Exception ex)
            {
                logger.Error(ex);
                return(new Response <StudentModel>(ConfigType.ERROR, ex.Message, null));
            }
        }
コード例 #2
0
        public StudentModel ConvertStudent(cms_Student cmsStudent)
        {
            try
            {
                StudentModel model = new StudentModel();
                model.StudentId = cmsStudent.StudentId;
                model.Name      = cmsStudent.Name;
                model.Address   = cmsStudent.Address;
                model.Email     = cmsStudent.Email;
                model.Facebook  = cmsStudent.Facebook;
                model.ClassId   = cmsStudent.ClassId;
                model.Phone     = cmsStudent.Phone;
                model.GroupId   = cmsStudent.GroupId;

                return(model);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(new StudentModel());
            }
        }