public async Task <int> Put([FromForm] ContactTypeModel contactTypeModel) { if (ModelState.IsValid) { if (contactTypeModel.FileChange) { if (!string.IsNullOrEmpty(contactTypeModel.Type.Icon)) { System.IO.File.Delete(contactTypeModel.Type.Icon[1..]);
public void IntegrationTest() { var connection = TestSession.GetConnection(); connection.Open(); #region good insertion and select by id test ContactTypeModel inserted = new ContactTypeModel(); inserted.Name = TestSession.Random.RandomString(50); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Insert(connection, new[] { inserted }); var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new ContactTypeModelPrimaryKey() { ContactTypeID = inserted.ContactTypeID, }); CollectionAssert.IsNotEmpty(selectedAfterInsertion); var selectedAfterInsert = selectedAfterInsertion.Single(); Assert.AreEqual(inserted.ContactTypeID, selectedAfterInsert.ContactTypeID); Assert.AreEqual(inserted.Name, selectedAfterInsert.Name); Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate); #endregion #region update and select by id test inserted.Name = TestSession.Random.RandomString(50); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Update(connection, new[] { inserted }); var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new ContactTypeModelPrimaryKey() { ContactTypeID = inserted.ContactTypeID, }); CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss); var selectedAfterUpdate = selectedAfterUpdateAddresss.Single(); Assert.AreEqual(inserted.ContactTypeID, selectedAfterUpdate.ContactTypeID); Assert.AreEqual(inserted.Name, selectedAfterUpdate.Name); Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate); #endregion #region delete test _tested.Delete(connection, new[] { inserted }); var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new ContactTypeModelPrimaryKey() { ContactTypeID = inserted.ContactTypeID, }); CollectionAssert.IsEmpty(selectedAfterDeleteAddresss); #endregion connection.Close(); }
/// <summary> /// To the view model. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public static ContactTypeViewModel ToViewModel(this ContactTypeModel model) { if (model == null) { return(null); } var entity = new ContactTypeViewModel { ContactTypeID = model.ContactTypeID, ContactType = model.ContactType }; return(entity); }
/// <summary> /// To the model. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public static ContactTypeModel ToModel(this ContactTypeViewModel entity) { if (entity == null) { return(null); } var model = new ContactTypeModel { ContactTypeID = entity.ContactTypeID, ContactType = entity.ContactType }; return(model); }