public appointment_hitchayvut ConvertModelToEntity(AppointmentHitchayvutModel model, int userId = -1)
        {
            appointment_hitchayvut entity = new appointment_hitchayvut();

            if (model == null)
            {
                return(null);
            }

            entity.appointmentId = model.AppointmentId;
            entity.hitchayvutId  = model.Hitchayvut.Id;

            if (model.Id > 0)
            {
                entity.id = model.Id;
            }

            if (userId > 0)
            {
                if (entity.id > 0)
                {
                    entity.editedById   = userId;
                    entity.editedByDate = System.DateTime.Now;
                }
                else //entity.id <= 0
                {
                    entity.createdById   = userId;
                    entity.createdByDate = System.DateTime.Now;
                }
            }

            return(entity);
        }
        public AppointmentHitchayvutModel GetById(int id)
        {
            appointment_hitchayvut     entity = this._repository.GetById(id);
            AppointmentHitchayvutModel model  = this.ConvertEntityToModel(entity);

            return(model);
        }
        public int Insert(int appointmentId, int hitchayvutId, int userId)
        {
            AppointmentHitchayvutModel model = new AppointmentHitchayvutModel {
                Id = -1, AppointmentId = appointmentId, Hitchayvut = new HitchayvutModel {
                    Id = hitchayvutId
                }
            };
            appointment_hitchayvut entity = this.ConvertModelToEntity(model, userId);

            return(this._repository.Insert(entity));
        }
        public void GetById_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository        = new AppointmentHitchayvutRepository(context);
            var hitchayvutService = new HitchayvutService();
            var service           = new AppointmentHitchayvutService(repository, hitchayvutService);
            int id = 1;

            // Act
            AppointmentHitchayvutModel result = service.GetById(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.Id);
        }
        public void ConvertModelToEntity_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var service = new AppointmentHitchayvutService();
            AppointmentHitchayvutModel model = GetTestModel();

            // Act
            appointment_hitchayvut entity = service.ConvertModelToEntity(model);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(model.Id, entity.id);
            Assert.AreEqual(model.AppointmentId, entity.appointmentId);
            Assert.AreEqual(model.Hitchayvut.Id, entity.hitchayvutId);
        }
        public AppointmentHitchayvutModel ConvertEntityToModel(appointment_hitchayvut entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new AppointmentHitchayvutModel()
            {
                Id            = entity.id,
                AppointmentId = entity.appointmentId,
                Hitchayvut    = entity.hitchayvut == null ? null : _hitchayvutService.ConvertEntityToModel(entity.hitchayvut)
            };

            return(model);
        }
        public void ConvertEntityToModel_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var service = new AppointmentHitchayvutService();
            appointment_hitchayvut entity = context.appointment_hitchayvut.Where(x => x.id == 1).FirstOrDefault();

            // Act
            AppointmentHitchayvutModel model = service.ConvertEntityToModel(entity);

            // Assert
            Assert.IsNotNull(model);
            Assert.AreEqual(model.Id, entity.id);
            Assert.AreEqual(model.AppointmentId, entity.appointmentId);
            if (entity.hitchayvut == null)
            {
                Assert.AreEqual(model.Hitchayvut, null);
            }
            else
            {
                Assert.AreEqual(model.Hitchayvut.Id, entity.hitchayvutId);
            }
        }
        public int Update(AppointmentHitchayvutModel model, int userId)
        {
            appointment_hitchayvut entity = this.ConvertModelToEntity(model, userId);

            return(this._repository.Update(entity));
        }