コード例 #1
0
        public ActionResult Create(AppointmentTypeModel model)
        {
            if (ModelState.IsValid)
            {
                var appointmentType = new AppointmentType
                {
                    Id   = model.Id,
                    Name = model.Name,
                    DefaultSeanceQuantity    = model.DefaultSeanceQuantity,
                    AppointmentPeriodeTypeId = model.AppointmentPeriodeTypeId,
                };

                _appointmentTypeService.InsertAppointmentType(appointmentType);

                if (string.IsNullOrEmpty(Request["saveandcontinue"]))
                {
                    return(RedirectToAction("List"));
                }

                if (string.IsNullOrEmpty(Request["save"]))
                {
                    return(RedirectToAction("Edit", new { id = appointmentType.Id }));
                }
            }

            return(RedirectToAction("List"));
        }
コード例 #2
0
        public ActionResult Edit(AppointmentTypeModel model)
        {
            if (ModelState.IsValid)
            {
                var appointmentType = _appointmentTypeService.GetAppointmentTypeById(model.Id);

                if (appointmentType == null || appointmentType.Deleted)
                {
                    return(RedirectToAction("List"));
                }

                appointmentType.Id   = model.Id;
                appointmentType.Name = model.Name;
                appointmentType.DefaultSeanceQuantity    = model.DefaultSeanceQuantity;
                appointmentType.AppointmentPeriodeTypeId = model.AppointmentPeriodeTypeId;

                _appointmentTypeService.UpdateAppointmentType(appointmentType);

                if (string.IsNullOrEmpty(Request["save"]))
                {
                    return(RedirectToAction("List"));
                }
            }

            return(RedirectToAction("List"));
        }
コード例 #3
0
        public appointmentType ConvertModelToEntity(AppointmentTypeModel model, int userId = -1)
        {
            appointmentType entity = new appointmentType();

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

            entity.name      = model.Name;
            entity.isCurrent = model.IsCurrent;
            entity.isDefault = model.IsDefault;
            entity.length    = model.Length;

            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);
        }
コード例 #4
0
        public AppointmentTypeModel GetDefault()
        {
            appointmentType      entity = this._repository.GetDefault();
            AppointmentTypeModel model  = this.ConvertEntityToModel(entity);

            return(model);
        }
コード例 #5
0
 public IHttpActionResult Post(AppointmentTypeModel model, int userId)
 {
     try
     {
         int result = _service.Insert(model, userId);
         return(Ok(result));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message.ToString()));
     }
 }
コード例 #6
0
        public ActionResult Edit(int id)
        {
            var appointmentType = _appointmentTypeService.GetAppointmentTypeById(id);

            if (appointmentType == null || appointmentType.Deleted)
            {
                return(RedirectToAction("List"));
            }

            var model = new AppointmentTypeModel()
            {
                Id   = appointmentType.Id,
                Name = appointmentType.Name,
                DefaultSeanceQuantity    = appointmentType.DefaultSeanceQuantity,
                AppointmentPeriodeTypeId = appointmentType.AppointmentPeriodeTypeId,
            };

            model.AvailableAppointmentPeriodeTypes = new List <SelectListItem>
            {
                new SelectListItem
                {
                    Text  = "Saat",
                    Value = ((int)AppointmentPeriodeType.Hours).ToString(),
                },
                new SelectListItem
                {
                    Text  = "Gün",
                    Value = ((int)AppointmentPeriodeType.Days).ToString(),
                },
                new SelectListItem
                {
                    Text  = "Hafta",
                    Value = ((int)AppointmentPeriodeType.Weeks).ToString(),
                },
                new SelectListItem
                {
                    Text  = "Ay",
                    Value = ((int)AppointmentPeriodeType.Months).ToString(),
                },
                new SelectListItem
                {
                    Text  = "Yıl",
                    Value = ((int)AppointmentPeriodeType.Years).ToString(),
                },
            };
            //Seçili gelmesi için
            model.AvailableAppointmentPeriodeTypes.FirstOrDefault(f => f.Value == model.AppointmentPeriodeTypeId.ToString()).Selected = true;

            return(View(model));
        }
コード例 #7
0
        private AppointmentTypeModel GetDemoItem(bool isNew)
        {
            AppointmentTypeModel item = new AppointmentTypeModel()
            {
                Name = "Demo name", IsCurrent = true, IsDefault = false, Length = 15
            };

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

            return(item);
        }
コード例 #8
0
        public void GetDefault_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new AppointmentTypeRepository(context);
            var service    = new AppointmentTypeService(repository);

            // Act
            AppointmentTypeModel result = service.GetDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsDefault);
        }
コード例 #9
0
        public void GetById_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var repository = new AppointmentTypeRepository(context);
            var service    = new AppointmentTypeService(repository);
            int id         = 1;

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

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.Id);
        }
コード例 #10
0
        /// <summary>
        /// Converts viewmodel to model
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public static AppointmentTypeModel ToModel(this AppointmentTypeViewModel model)
        {
            if (model == null)
            {
                return(null);
            }
            var entity = new AppointmentTypeModel
            {
                AppointmentTypeID = model.AppointmentTypeID,
                AppointmentType   = model.AppointmentType,
                ProgramID         = model.ProgramID,
                ModifiedOn        = model.ModifiedOn
            };

            return(entity);
        }
コード例 #11
0
        /// <summary>
        /// To the view model.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static AppointmentTypeViewModel ToViewModel(this AppointmentTypeModel entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new AppointmentTypeViewModel
            {
                AppointmentTypeID = entity.AppointmentTypeID,
                AppointmentType   = entity.AppointmentType,
                ProgramID         = entity.ProgramID,
                ModifiedOn        = entity.ModifiedOn
            };

            return(model);
        }
コード例 #12
0
        public void ConvertModelToEntity_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            var service = new AppointmentTypeService();
            AppointmentTypeModel model = GetTestModel();

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

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(entity.name, model.Name);
            Assert.AreEqual(entity.isDefault, model.IsDefault);
            Assert.AreEqual(entity.isCurrent, model.IsCurrent);
            Assert.AreEqual(model.Length, entity.length);
        }
コード例 #13
0
        public void Put_Test()
        {
            // Arrange
            var mockService            = new Mock <IAppointmentTypeService>();
            var controller             = new AppointmentTypeController(mockService.Object);
            AppointmentTypeModel model = GetDemoItem(false);
            int userId = 1;

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

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.AreEqual(HttpStatusCode.Accepted, contentResult.StatusCode);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(model.Id, contentResult.Content.Id);
        }
コード例 #14
0
        public AppointmentTypeModel ConvertEntityToModel(appointmentType entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new AppointmentTypeModel()
            {
                Id        = entity.id,
                Name      = entity.name.Trim(),
                IsCurrent = entity.isCurrent,
                IsDefault = entity.isDefault == null ? false : (bool)entity.isDefault,
                Length    = entity.length
            };

            return(model);
        }
コード例 #15
0
        public void ConvertEntityToModel_Test()
        {
            // Arrange
            TestKolgraphEntities context = new TestKolgraphEntities();
            //var repository = new AppointmentTypeRepository(context);
            var             service = new AppointmentTypeService();
            appointmentType entity  = context.appointmentType.Where(x => x.id == 1).FirstOrDefault();

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

            // Assert
            Assert.IsNotNull(model);
            Assert.AreEqual(model.Id, entity.id);
            Assert.AreEqual(model.Name, entity.name);
            Assert.AreEqual(model.IsDefault, entity.isDefault);
            Assert.AreEqual(model.IsCurrent, entity.isCurrent);
            Assert.AreEqual(model.Length, entity.length);
        }
コード例 #16
0
        public ActionResult Create()
        {
            var model = new AppointmentTypeModel
            {
                AvailableAppointmentPeriodeTypes = new List <SelectListItem>
                {
                    new SelectListItem
                    {
                        Text  = "Saat",
                        Value = ((int)AppointmentPeriodeType.Hours).ToString(),
                    },
                    new SelectListItem
                    {
                        Text  = "Gün",
                        Value = ((int)AppointmentPeriodeType.Days).ToString(),
                    },
                    new SelectListItem
                    {
                        Text  = "Hafta",
                        Value = ((int)AppointmentPeriodeType.Weeks).ToString(),
                    },
                    new SelectListItem
                    {
                        Text  = "Ay",
                        Value = ((int)AppointmentPeriodeType.Months).ToString(),
                    },
                    new SelectListItem
                    {
                        Text  = "Yıl",
                        Value = ((int)AppointmentPeriodeType.Years).ToString(),
                    },
                }
            };

            return(View(model));
        }
コード例 #17
0
        public IHttpActionResult Put(AppointmentTypeModel model, int userId)
        {
            int result = _service.Update(model, userId);

            return(Content(System.Net.HttpStatusCode.Accepted, model));
        }
コード例 #18
0
        public int Update(AppointmentTypeModel model, int userId)
        {
            appointmentType entity = this.ConvertModelToEntity(model, userId);

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