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 appointmentType GetDefault() { using (var context = this._context) { appointmentType entity = context.appointmentType.Where(i => (bool)i.isDefault).FirstOrDefault(); return(entity); } }
public appointmentType GetById(Int64 id) { using (var context = this._context) { appointmentType entity = context.appointmentType.AsNoTracking() .Where(x => x.id == id) .FirstOrDefault(); return(entity); } }
public void GetDefault_Test() { // Arrange TestKolgraphEntities context = new TestKolgraphEntities(); var repository = new AppointmentTypeRepository(context); // Act appointmentType result = repository.GetDefault(); // Assert Assert.IsNotNull(result); Assert.IsTrue((bool)result.isDefault); }
public void GetById_Test() { // Arrange TestKolgraphEntities context = new TestKolgraphEntities(); var repository = new AppointmentTypeRepository(context); int id = 1; // Act appointmentType result = repository.GetById(id); // Assert Assert.IsNotNull(result); Assert.AreEqual(id, result.id); }
public int Insert(appointmentType entity) { // TODO: // check if trying to insert default when default already exists if (entity == null) { return(-1); } using (var context = this._context) { context.appointmentType.Add(entity); var result = context.SaveChanges(); return(result); } }
public int Update(appointmentType entity) { // TO DO: // check if trying to create default when default already exists if (entity == null) { return(-1); } using (var context = this._context) { context.MarkAsModified(entity); var result = context.SaveChanges(); return(entity.id); } }
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 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 int Update(AppointmentTypeModel model, int userId) { appointmentType entity = this.ConvertModelToEntity(model, userId); return(this._repository.Update(entity)); }
public void MarkAsModified(appointmentType item) { }