/// <summary> /// Delete the With Attach Entiy. /// </summary> /// <param name="Entiy">The Entiy.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> public bool DeleteWithAttachEntiy(AddressDto t) { var dbEntity = typeAdapter.ConvertDtoToEntities(t); entiesrepository.Attach(dbEntity); entiesrepository.Delete(dbEntity); entiesrepository.Save(); return(true); }
public void DeleteWithIdThatDoesntExistThrowsException() { int id = 1000; // arrange (use the context directly - we assume that works) var options = new DbContextOptionsBuilder <Project1Context>() .UseInMemoryDatabase("db_address_test_delete").Options; using (var db = new Project1Context(options)); // act (for act, only use the repo, to test it) //using (var db = new Project1Context(options)) //{ //var repo = new AddressRepository(db); //Addresses Address = new Addresses { Name = "Test Delete", Stock = 10 }; //repo.Save(Address); //repo.SaveChanges(); //id = Address.Id; //} // assert (for assert, once again use the context directly for verify.) using (var db = new Project1Context(options)) { var repo = new AddressRepository(db); Addresses Address = (Addresses)repo.GetById(id); Assert.Null(Address); Assert.Throws <ArgumentException>(() => repo.Delete(id)); } }
public void Delete(string[] args) { if (string.IsNullOrEmpty(currentTable)) { Console.WriteLine("Please select a Table first"); return; } Int32.TryParse(args[0], out int Id); bool result; switch (currentTable) { case "Address": result = addressRepository.Delete(Id); Console.WriteLine(result ? "Successfully deleted" : "Not found"); break; case "Company": result = companyRepository.Delete(Id); Console.WriteLine(result ? "Successfully deleted" : "Not found"); break; case "Department": result = departmentRepository.Delete(Id); Console.WriteLine(result ? "Successfully deleted" : "Not found"); break; case "Employee": result = employeeRepository.Delete(Id); Console.WriteLine(result ? "Successfully deleted" : "Not found"); break; } }
public void Address_Repository_Create_List_Delete() { //get quantity before actions var lst = _objRepo.GetAll().ToList(); var initialCount = lst.Count; //Arrange - City, State PostalCode required var obj = new Entity.Model.Address { Line1 = "1000 Exit Ave", City = "NewCity", State = "NY", PostalCode = "11020", Country = "USA" }; //Act var result = _objRepo.Add(obj); _databaseContext.SaveChanges(); lst = _objRepo.GetAll().ToList(); //Assert Assert.AreEqual(initialCount + 1, lst.Count); Assert.AreEqual("NewCity", lst.Last().City); //Remove last added obj var dP = _objRepo.Delete(obj); _databaseContext.SaveChanges(); lst = _objRepo.GetAll().ToList(); //Assert Assert.AreEqual(initialCount, lst.Count); }
public async Task <IActionResult> Delete(int addressId) { try { var addressAux = await _repo.GetAddressByIdAsync(addressId); if (addressAux == null) { return(NotFound()); } _repo.Delete(addressAux); if (await _repo.SaveChangesAsync()) { return(Ok("Enderço excluído com sucesso")); } } catch (System.Exception ex) { return(this.StatusCode( StatusCodes.Status500InternalServerError, "Erro ao excluir o endereço\n" + ex.InnerException)); } return(BadRequest()); }
public void AddressRepositoryCRUDTest() { var context = new NoodleDbContext("NoodleDb"); context.Init(); IAddressRepository repository = new AddressRepository(context); var id = Guid.NewGuid(); var record = new Address { Id = id, City = "_City", Country = "_Contry", Elevation = 0.1f, Latitude = 0.1f, Line1 = "_Line1" + id.ToString(), Line2 = "_Line2" + id.ToString(), Longitude = 0.1f, Postalcode = "_Postalcode", Type = "_Type" }; repository.Create(record); record.City = "U_" + record.City; record.Country = "U_" + record.Country; record.Line1 = "U_" + record.Line1; record.Line2 = "U_" + record.Line2; record.Postalcode = "U_" + record.Postalcode; record.Type = "U_" + record.Type; record.Elevation = 0.2f; record.Latitude = 0.2f; record.Longitude = 0.2f; repository.Update(record); var UpdatedRecord = repository.GetById(id); Assert.AreEqual(record.Id, UpdatedRecord.Id); Assert.AreEqual(record.City, UpdatedRecord.City); Assert.AreEqual(record.Country, UpdatedRecord.Country); Assert.AreEqual(record.Line1, UpdatedRecord.Line1); Assert.AreEqual(record.Line2, UpdatedRecord.Line2); Assert.AreEqual(record.Postalcode, UpdatedRecord.Postalcode); Assert.AreEqual(record.Type, UpdatedRecord.Type); Assert.AreEqual(record.Elevation, UpdatedRecord.Elevation); Assert.AreEqual(record.Latitude, UpdatedRecord.Latitude); Assert.AreEqual(record.Longitude, UpdatedRecord.Longitude); repository.Delete(record.Id); var deletedRecord = repository.GetById(id); Assert.IsNull(deletedRecord); }
[Route("api/requestAd/{id}")] //deleting ad public IHttpActionResult Delete(int id) { var adr = adRepo.Get(id); adRepo.Delete(id); specRepo.Delete(adr.SpecId); addressRepo.Delete(adr.AddressId); return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Delete(int id) { var Ad = adRepo.Get(id); adRepo.Delete(id); specificationRepo.Delete(Ad.SpecId); addressRepo.Delete(Ad.AddressId); return(StatusCode(HttpStatusCode.NoContent)); }
public void ShouldDeleteAddressOnFakeDataBaseWhenGiveId() { var addressId = _fakeContext.Addreses.FirstOrDefault().Id; var address = _addressRepository.Get(addressId); _addressRepository.Delete(address); _uow.Commit(); Assert.AreEqual(2, _fakeContext.Addreses.Count()); }
internal void DeleteAddress(int id, int contactId) { var aRep = new AddressRepository(_uow); var addresses = GetCustomerAddresses(contactId); var origAddress = addresses.First(a => a.addressID == id); aRep.Delete(origAddress); _uow.Save(); RetrieveAndStoreCustomerGraph(contactId); }
public void DeleteWorks() { int id = 0; // arrange (use the context directly - we assume that works) var options = new DbContextOptionsBuilder <Project1Context>() .UseInMemoryDatabase("db_address_test_delete").Options; using (var db = new Project1Context(options)); // act (for act, only use the repo, to test it) using (var db = new Project1Context(options)) { var customerRepo = new CustomerRepository(db); var repo = new AddressRepository(db); //Create customer Customers customer = new Customers { FirstName = "First Name", LastName = "Last Name" }; customerRepo.Save(customer); customerRepo.SaveChanges(); Addresses address = new Addresses { CustomerId = customer.Id, Address1 = "Ad1 Test Delete", City = "City Delete", State = "ST", Zipcode = 12345 }; repo.Save(address); customerRepo.SaveChanges(); id = address.Id; } // assert (for assert, once again use the context directly for verify.) using (var db = new Project1Context(options)) { var repo = new AddressRepository(db); Addresses address = (Addresses)repo.GetById(id); Assert.Equal(id, address.Id); Assert.Equal("Ad1 Test Delete", address.Address1); Assert.Equal("City Delete", address.City); Assert.Equal("ST", address.State); Assert.Equal(12345, address.Zipcode); repo.Delete(id); repo.SaveChanges(); address = (Addresses)repo.GetById(id); Assert.Null(address); } }
private void DeleteAddress(object sender, EventArgs e) { var address = addressRepository.GetByPatientId(patientId); if (addressRepository.Delete(address) > 0) { MessageBox.Show("Deleted Successfully"); } ClearAddressFields(); FillDataGridView(); }
public bool Delete(long userId, Address toDelete) { using (var tran = new TransactionScope()) { var toRet = _repository.Delete(toDelete); BlLog.Log(userId, Module, "Delete address", "AddressDeleted", new object[] { toDelete.Sequence, toDelete.Entity.Pin, BlEntity.FormatFullName(toDelete.Entity) }); tran.Complete(); return(toRet); } }
// methode api pour fair le lien a mon repository delete public bool Delete(int id) { AddressRepository repo = new AddressRepository(); try { return(repo.Delete(id)); } catch (Exception) { throw new HttpResponseException(HttpStatusCode.NotFound); } }
public async Task <IActionResult> DeleteAddress(int addressId) { var address = await _repo.GetAddress(addressId); _repo.Delete(address); if (await _repo.SaveAll()) { return(NoContent()); } return(BadRequest()); }
static void CheckDbUpdateConcurrencyExceptionWithDifferentUnitOfWorkAndContext() { var connectionString = ConfigurationManager.ConnectionStrings["BankDepositsDatabase"].ConnectionString; var optionsBuilder = new DbContextOptionsBuilder <BankDepositsContext>() .UseSqlServer(connectionString); using (var context1 = new BankDepositsContext(optionsBuilder.Options)) { var rand = new Random(); var unitOfWork = new UnitOfWork(context1); IAddressRepository addressRepository = new AddressRepository(unitOfWork); var address = new Address(); addressRepository.Create(address); address.Apartment = 5; address.House = 10; address.Housing = "A"; address.Street = new Street() { Locality = new Locality() { LocalityName = "Partizanski" + rand.NextDouble(), LocalityType = LocalityType.City, Region = "Minsk" }, StreetName = "Frolikova", Postcode = 220037 }; addressRepository.Commit().Wait(); var addresses = addressRepository.GetBy(null, a => a.Street).ToListAsync().Result; PrintAddresses(addresses); using (var context2 = new BankDepositsContext(optionsBuilder.Options)) { var unitOfWork2 = new UnitOfWork(context2); unitOfWork2.ExecuteQuery("Delete from dbo.Addresses where address_id = " + address.Id).Wait(); } addressRepository.Delete(address); addressRepository.Commit().Wait(); addresses = addressRepository.GetBy(null, a => a.Street).ToListAsync().Result; PrintAddresses(addresses); } Console.ReadLine(); }
public static void DeleteAddress() { IRepository <Address> repository = new AddressRepository(); try { repository.Delete(1); Console.WriteLine("Silme başarılı"); } catch (Exception e) { Console.WriteLine("Bir Hata Oluştu: " + e); } Console.ReadKey(); }
public async Task <bool> DeleteAddress(int id) { Address address = await _addressRepository.Delete(id); if (address == null) { return(false); } else { await _addressRepository.SaveChanges(); return(true); } }
/// <summary> /// Metodo para remover um registro criado /// </summary> /// <param name="id"></param> /// <returns>se foi realizado com sucesso a exclusão do registro</returns> public static dynamic Remove(int id) { try { _Address.Delete(new Func <Address, bool>((x) => x.IdRecord == id)); _Address.SaveDatabase(); _Register.Delete(new Func <Register, bool>((x) => x.Id == id)); _Register.SaveDatabase(); return(StatusCodes.Status200OK); } catch (Exception) { return(StatusCodes.Status400BadRequest); } }
public ResponseMessage Delete(int id) { ResponseMessage response = new ResponseMessage(); var oldAddress = _repository.GetById(id); if (oldAddress.Payments.Count() > 0) { response.IsError = true; response.ErrorCodes.Add("Payment already exist for this Address, it can't be deleted."); return(response); } _repository.Delete(id); return(response); }
protected void lnkDelete_Click(object sender, EventArgs e) { LinkButton button = (sender as LinkButton); int addressId = Convert.ToInt32(button.CommandArgument); using (AddressRepository repository = new AddressRepository()) { var address = repository.Delete(addressId); if (address != null) { SuccessMessage.Text = "Address has been deleted successfully !!"; } else { ErrorMessage.Text = "Some error occurred. Please contact your system administrator."; } } BindAddressBook(); }
public async Task Delete(AddressModel model) { await _repository.Delete(model); }
public ActionResult Delete(int id, FormCollection collection) { ClientDetailAddress clientDetailAddress = new ClientDetailAddress(); clientDetailAddress = clientDetailAddressRepository.GetAddressClientDetail(id); //Check Exists if (clientDetailAddress == null) { ViewData["ActionMethod"] = "DeletePost"; return(View("RecordDoesNotExistError")); } int clientDetailId = clientDetailAddress.ClientDetailId; ClientDetailClientSubUnitTravelerType clientDetailClientSubUnitTravelerType = new ClientDetailClientSubUnitTravelerType(); clientDetailClientSubUnitTravelerType = clientDetailClientSubUnitTravelerTypeRepository.GetClientDetailClientSubUnitTravelerType(clientDetailId); //Check Exists if (clientDetailClientSubUnitTravelerType == null) { ViewData["ActionMethod"] = "DeletePost"; return(View("RecordDoesNotExistError")); } string csu = clientDetailClientSubUnitTravelerType.ClientSubUnitGuid; string tt = clientDetailClientSubUnitTravelerType.TravelerTypeGuid; ClientSubUnit clientSubUnit = new ClientSubUnit(); clientSubUnit = clientSubUnitRepository.GetClientSubUnit(csu); //Access Rights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToClientSubUnit(csu)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } Address address = new Address(); address = addressRepository.GetAddress(id); //Delete Item try { address.VersionNumber = Int32.Parse(collection["Address.VersionNumber"]); addressRepository.Delete(address); } catch (SqlException ex) { //Versioning Error - go to standard versionError page if (ex.Message == "SQLVersioningError") { ViewData["ReturnURL"] = "/ClientSubUnitAddress.mvc/Delete/" + id.ToString(); return(View("VersionError")); } //Generic Error ViewData["Message"] = "There was a problem with your request, please see the log file or contact an administrator for details"; return(View("Error")); } return(RedirectToAction("List", new { id = clientDetailId })); }
public long Delete(int id) { return(_repo.Delete(id)); }
public Response <Model.Customer> Delete(Model.Customer customer) { ICustomerRepository customerRepository = null; IAddressRepository addressRepository = null; Validator <Model.Customer> validator = ValidationFactory.CreateValidator <Model.Customer>("Delete"); try { #region Validation if (!validator.Validate(customer).IsValid) { response.Status = ResponseStatus.ErrorValidation; response.ErrorValue = (int)ErrorCode.InvalidData; foreach (var result in validator.Validate(customer)) { if (!response.Validations.ContainsKey(result.Key)) { response.Validations.Add(result.Key, result.Message); } } return(response); } #endregion Validation using (var ctx = new ChickenScratchContext()) { customerRepository = new CustomerRepository(ctx); // Find Customer customer = customerRepository.GetBy(customer); if (customer == null) { response.Validations.Add("Customer", "Customer does not exist"); response.ErrorValue = (Int32)ErrorCode.InvalidCustomerId; return(response); } // Delete Customer customerRepository.Delete(customer); if (customer.Addresses.Count > 0) { addressRepository = new AddressRepository(ctx); // Delete Adrress(es) foreach (Model.Address address in customer.Addresses) { addressRepository.Delete(address); } } customerRepository.Save(); response.Result = customer; response.Status = ResponseStatus.Success; return(response); } } catch (Exception ex) { throw ex; } }
public bool Delete(Address address) { return(_addressRepository.Delete(address)); }