예제 #1
0
        public HitchayvutModel GetById(int id)
        {
            hitchayvut      entity = this._repository.GetById(id);
            HitchayvutModel model  = this.ConvertEntityToModel(entity);

            return(model);
        }
예제 #2
0
 public IHttpActionResult Post(HitchayvutModel model, int userId)
 {
     try
     {
         int result = _service.Insert(model, userId);
         return(Ok(result));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message.ToString()));
     }
 }
        private HitchayvutModel GetDemoItem(bool isNew)
        {
            HitchayvutModel item = new HitchayvutModel()
            {
                Number = "111", Date = new System.DateTime(), IsUsed = false, NumberAllocated = 0, NumberAppointments = 0, NumberUsed = 0, PatientId = 2
            };

            if (!isNew)
            {
                item.Id = 1;
            }

            return(item);
        }
예제 #4
0
        public void GetById_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new HitchayvutRepository(context);
            var service    = new HitchayvutService(repository);
            int id         = 1;

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

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.Id);
        }
        public void Post_Test()
        {
            // Arrange
            var             mockService = new Mock <IHitchayvutService>();
            var             controller  = new HitchayvutController(mockService.Object);
            HitchayvutModel model       = GetDemoItem(true);
            int             userId      = 1;

            // Act
            IHttpActionResult actionResult = controller.Post(model, userId);
            var createdResult = actionResult as OkNegotiatedContentResult <int>;

            // Assert
            Assert.IsNotNull(createdResult);
            //Assert.AreEqual("DefaultApi", createdResult.RouteName);
            Assert.IsTrue(createdResult.Content >= 0);
        }
        public void Put_Test()
        {
            // Arrange
            var             mockService = new Mock <IHitchayvutService>();
            var             controller  = new HitchayvutController(mockService.Object);
            HitchayvutModel model       = GetDemoItem(false);
            int             userId      = 1;

            // Act
            IHttpActionResult actionResult = controller.Put(model, userId);
            var contentResult = actionResult as NegotiatedContentResult <HitchayvutModel>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.AreEqual(HttpStatusCode.Accepted, contentResult.StatusCode);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(model.Id, contentResult.Content.Id);
        }
예제 #7
0
        public void ConvertModelToEntity_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var             service      = new HitchayvutService();
            HitchayvutModel model        = GetTestModel();

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

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(model.Number, entity.number);
            Assert.AreEqual(model.Date, entity.date);
            Assert.AreEqual(model.PatientId, entity.patientId);
            Assert.AreEqual(model.NumberAllocated, entity.numberAllocated);
            Assert.AreEqual(model.NumberAppointments, entity.numberAppointments);
            Assert.AreEqual(model.NumberUsed, entity.numberUsed);
            Assert.AreEqual(model.IsUsed, entity.isUsed);
        }
예제 #8
0
        public HitchayvutModel ConvertEntityToModel(hitchayvut entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new HitchayvutModel()
            {
                Id                 = entity.id,
                Number             = entity.number.Trim(),
                Date               = entity.date,
                PatientId          = entity.patientId,
                NumberAppointments = entity.numberAppointments,
                NumberAllocated    = (int)entity.numberAllocated,
                NumberUsed         = (int)entity.numberUsed,
                IsUsed             = entity.isUsed
            };

            return(model);
        }
예제 #9
0
        public void ConvertEntityToModel_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var        service           = new HitchayvutService();
            hitchayvut entity            = context.hitchayvut.Where(x => x.id == 1).FirstOrDefault();

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

            // Assert
            Assert.IsNotNull(model);
            Assert.AreEqual(model.Id, entity.id);
            Assert.AreEqual(model.Number, entity.number);
            Assert.AreEqual(model.Date, entity.date);
            Assert.AreEqual(model.PatientId, entity.patientId);
            Assert.AreEqual(model.NumberAllocated, entity.numberAllocated);
            Assert.AreEqual(model.NumberAppointments, entity.numberAppointments);
            Assert.AreEqual(model.NumberUsed, entity.numberUsed);
            Assert.AreEqual(model.IsUsed, entity.isUsed);
        }
예제 #10
0
        public hitchayvut ConvertModelToEntity(HitchayvutModel model, int userId = -1)
        {
            hitchayvut entity = new hitchayvut();

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

            entity.number             = model.Number;
            entity.date               = model.Date;
            entity.patientId          = model.PatientId;
            entity.numberAppointments = model.NumberAppointments;
            entity.numberAllocated    = model.NumberAllocated;
            entity.numberUsed         = model.NumberUsed;
            entity.isUsed             = model.IsUsed;

            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);
        }
예제 #11
0
        public int Update(HitchayvutModel model, int userId)
        {
            hitchayvut entity = this.ConvertModelToEntity(model, userId);

            return(this._repository.Update(entity));
        }
예제 #12
0
        public IHttpActionResult Put(HitchayvutModel model, int userId)
        {
            int result = _service.Update(model, userId);

            return(Content(System.Net.HttpStatusCode.Accepted, model));
        }