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")); }
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")); }
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); }
public AppointmentTypeModel GetDefault() { appointmentType entity = this._repository.GetDefault(); AppointmentTypeModel model = this.ConvertEntityToModel(entity); return(model); }
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())); } }
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)); }
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); }
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); }
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); }
/// <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); }
/// <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); }
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); }
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); }
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); }
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); }
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)); }
public IHttpActionResult Put(AppointmentTypeModel model, int userId) { int result = _service.Update(model, userId); return(Content(System.Net.HttpStatusCode.Accepted, model)); }
public int Update(AppointmentTypeModel model, int userId) { appointmentType entity = this.ConvertModelToEntity(model, userId); return(this._repository.Update(entity)); }