public Model.Teacher Convert(TeacherParam param, Model.Teacher oldEntity)
        {
            Model.Teacher entity = null;

            if (oldEntity != null)
            {
                entity = oldEntity;
            }
            else
            {
                entity = new Model.Teacher()
                {
                    Code        = param.Code,
                    Id          = param.Id,
                    Description = param.Description,
                    Name        = param.Name
                };
            }

            entity.FirstName   = param.FirstName;
            entity.LastName    = param.LastName;
            entity.MiddleName  = param.MiddleName;
            entity.Address     = param.Address;
            entity.MobilePhone = param.MobilePhone;
            entity.HomePhone   = param.HomePhone;
            entity.Email       = param.Email;

            entity.User   = UserDao.Find(param.UserId);
            entity.Status = StatusDao.Find(param.StatusId);

            return(entity);
        }
        //public TeacherProcessor(ITeacherDao dao, ITeacherParamConverter paramConverter,
        //    ITeacherResultConverter resultConverter)
        //{
        //    this.Dao = dao;
        //    this.ParamConverter = paramConverter;
        //    this.ResultConverter = resultConverter;
        //}

        public TeacherResult Create(TeacherParam param)
        {
            Model.Teacher entity = ParamConverter.Convert(param, null);

            entity = Dao.Save(entity);

            return(ResultConverter.Convert(entity));
        }
        public void Update(long id, TeacherParam param)
        {
            Model.Teacher oldEntity = Dao.Find(id);

            if (oldEntity != null)
            {
                Dao.Delete(oldEntity);
                Dao.Update(ParamConverter.Convert(param, null));
            }
            else
            {
                Console.WriteLine($"No entity with Id = {id}  was found");
            }
        }
Beispiel #4
0
        //public TeacherService(ITeacherProcessor processor)
        //{
        //    this.Processor = processor;
        //}

        /// <summary>
        /// Function to create new a entity .
        /// </summary>
        /// <param name="param">a entity</param>
        /// <returns>response and new entity</returns>
        public ApiResponse Create(TeacherParam param)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                response.Text = $"The entity successfully added .\n" +
                                $" {Serialization.Serizlize(Processor.Create(param))}";
                response.Result = true;

                return(response);
            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Text   = ex.Message;

                return(response);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Function to update information about a entity .
        /// </summary>
        /// <param name="id">entity's id</param>
        /// <param name="param">entity</param>
        /// <returns>response and update entity</returns>
        public ApiResponse Update(long id, TeacherParam param)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                Processor.Update(id, param);
                response.Text   = "The entity updated successfully . \n";
                response.Result = true;

                return(response);
            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Text   = ex.Message;

                return(response);
            }
        }
Beispiel #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="param">a entity</param>
 public void ValidateParameters(TeacherParam param)
 {
     throw new NotImplementedException();
 }