// POST: api/LookupType public HttpResponseMessage Post([FromBody] AddressTypeModel addressType) { int addressTypeId = _addressTypeServices.Create(addressType); return(addressTypeId > 0 ? Request.CreateResponse(HttpStatusCode.OK, addressTypeId) : Request.CreateResponse(HttpStatusCode.Conflict, "Address Type with this name exists.")); }
public void IntegrationTest() { var connection = TestSession.GetConnection(); connection.Open(); #region good insertion and select by id test AddressTypeModel inserted = new AddressTypeModel(); inserted.Name = TestSession.Random.RandomString(50); inserted.rowguid = Guid.NewGuid(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Insert(connection, new[] { inserted }); var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new AddressTypeModelPrimaryKey() { AddressTypeID = inserted.AddressTypeID, }); CollectionAssert.IsNotEmpty(selectedAfterInsertion); var selectedAfterInsert = selectedAfterInsertion.Single(); Assert.AreEqual(inserted.AddressTypeID, selectedAfterInsert.AddressTypeID); Assert.AreEqual(inserted.Name, selectedAfterInsert.Name); Assert.AreEqual(inserted.rowguid, selectedAfterInsert.rowguid); Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate); #endregion #region update and select by id test inserted.Name = TestSession.Random.RandomString(50); inserted.rowguid = Guid.NewGuid(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Update(connection, new[] { inserted }); var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new AddressTypeModelPrimaryKey() { AddressTypeID = inserted.AddressTypeID, }); CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss); var selectedAfterUpdate = selectedAfterUpdateAddresss.Single(); Assert.AreEqual(inserted.AddressTypeID, selectedAfterUpdate.AddressTypeID); Assert.AreEqual(inserted.Name, selectedAfterUpdate.Name); Assert.AreEqual(inserted.rowguid, selectedAfterUpdate.rowguid); Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate); #endregion #region delete test _tested.Delete(connection, new[] { inserted }); var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new AddressTypeModelPrimaryKey() { AddressTypeID = inserted.AddressTypeID, }); CollectionAssert.IsEmpty(selectedAfterDeleteAddresss); #endregion connection.Close(); }
public static AddressType ToDomain(this AddressTypeModel model, AddressType domain) { if (model != null) { domain.Id = model.Id; domain.Type = model.Type; } return(domain); }
static void Main(string[] args) { AddressTypeModel newAddressTypeModel = new AddressTypeModel(); PhoneTypeModel newPhoneTypeModel = new PhoneTypeModel(); StateModel newStateModel = new StateModel(); AddressModel newAddressModel = new AddressModel(); PhoneModel newPhoneModel = new PhoneModel(); ContactModel newContactModel = new ContactModel(); CustomerModel newCustomerModel = new CustomerModel(); JObject o = (JObject)JToken.FromObject(newAddressTypeModel); Console.WriteLine("AddressType Model"); Console.WriteLine("************************************"); Console.Write(o.ToString()); o = (JObject)JToken.FromObject(newPhoneTypeModel); Console.WriteLine(); Console.WriteLine("PhoneType Model"); Console.WriteLine("************************************"); Console.Write(o.ToString()); o = (JObject)JToken.FromObject(newStateModel); Console.WriteLine(); Console.WriteLine("State Model"); Console.WriteLine("************************************"); Console.Write(o.ToString()); o = (JObject)JToken.FromObject(newAddressModel); Console.WriteLine(); Console.WriteLine("Address Model"); Console.WriteLine("************************************"); Console.Write(o.ToString()); o = (JObject)JToken.FromObject(newPhoneModel); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Phone Model"); Console.WriteLine("************************************"); Console.Write(o.ToString()); o = (JObject)JToken.FromObject(newContactModel); Console.WriteLine(); Console.WriteLine("Contact Model"); Console.WriteLine("************************************"); Console.Write(o.ToString()); o = (JObject)JToken.FromObject(newCustomerModel); Console.WriteLine(); Console.WriteLine("Customer Model"); Console.WriteLine("************************************"); Console.Write(o.ToString()); Console.ReadKey(); }
public static AddressTypeModel ToModel(this AddressType domain) { var model = new AddressTypeModel(); if (domain != null) { model.Id = domain.Id; model.Type = domain.Type; } return(model); }
public static AddressType ToDomain(this AddressTypeModel model) { var domain = new AddressType(); if (model != null) { domain.Id = model.Id; domain.Type = model.Type; } return(domain); }
/// <summary> /// To the view model. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public static AddressTypeViewModel ToViewModel(this AddressTypeModel model) { if (model == null) { return(null); } var entity = new AddressTypeViewModel { AddressTypeID = model.AddressTypeID, AddressType = model.AddressType }; return(entity); }
/// <summary> /// To the model. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public static AddressTypeModel ToModel(this AddressTypeViewModel entity) { if (entity == null) { return(null); } var model = new AddressTypeModel { AddressTypeID = entity.AddressTypeID, AddressType = entity.AddressType }; return(model); }
/// <summary> /// Fetches address type details by id /// </summary> /// <param name="id"></param> /// <returns></returns> public AddressTypeModel GetById(int id) { var addressType = _dbActions.AddressTypeRepository.GetById(id); if (addressType != null) { AddressTypeModel addressTypeEntity = new AddressTypeModel() { Id = addressType.Id, AddressType = addressType.AddressType, Archived = addressType.Archived }; return(addressTypeEntity); } return(null); }
/// <summary> /// Creates a address type /// </summary> /// <param name="addressTypeModel"></param> /// <returns></returns> public int Create(AddressTypeModel addressTypeModel) { using (var scope = new TransactionScope()) { var addressType = new AddressTypeLookup() { AddressType = addressTypeModel.AddressType, Archived = addressTypeModel.Archived }; var addressTypeCheck = _dbActions.AddressTypeRepository.GetSingle(p => p.AddressType == addressTypeModel.AddressType); if (addressTypeCheck == null) { _dbActions.AddressTypeRepository.Insert(addressType); _dbActions.Save(); scope.Complete(); return(addressType.Id); } scope.Complete(); return(-1); } }
/// <summary> /// Updates a lookup type /// </summary> /// <param name="id"></param> /// <param name="addressTypeModel"></param> /// <returns></returns> public bool Update(int id, AddressTypeModel addressTypeModel) { var success = false; if (addressTypeModel != null) { using (var scope = new TransactionScope()) { var addressType = _dbActions.AddressTypeRepository.GetById(id); if (addressType != null) { addressType.AddressType = addressTypeModel.AddressType; addressType.Archived = addressTypeModel.Archived; _dbActions.AddressTypeRepository.Update(addressType); _dbActions.Save(); scope.Complete(); success = true; } } } return(success); }
/// <summary> /// Fetches all the address types. /// </summary> /// <param name="includeArchived"></param> /// <returns></returns> public IEnumerable <AddressTypeModel> GetAll(bool includeArchived) { var addressTypes = includeArchived ? _dbActions.AddressTypeRepository.GetAll().ToList() : _dbActions.AddressTypeRepository.GetMany(p => p.Archived == false).ToList(); if (!addressTypes.Any()) { return(null); } List <AddressTypeModel> addressTypeEntities = new List <AddressTypeModel>(); foreach (AddressTypeLookup addressType in addressTypes) { AddressTypeModel addressTypeEntity = new AddressTypeModel() { Id = addressType.Id, AddressType = addressType.AddressType, Archived = addressType.Archived }; addressTypeEntities.Add(addressTypeEntity); } return(addressTypeEntities); }
// PUT: api/LookupType/5 public bool Put(int id, [FromBody] AddressTypeModel addressType) { return(id > 0 && _addressTypeServices.Update(id, addressType)); }