public HttpResponseMessage Delete(Guid id) { bool boolValueReply = true; try { if (dao.Delete(id)) { httpStatus = HttpStatusCode.OK; replyMessage = "Endereço deletado com sucesso"; } else { boolValueReply = false; throw new System.InvalidOperationException("Erro ao deletar endereço, por favor contate o suporte"); } } catch (Exception ex) { httpStatus = HttpStatusCode.InternalServerError; replyMessage = ex.Message; } return(Request.CreateResponse(httpStatus, boolValueReply)); }
public ActionResult Delete(int id) { try { UserDao uDao = new UserDao(); AddressDao aDao = new AddressDao(); FitnessUser fitnessUser = uDao.GetById(id); Address address = new Address(); address = fitnessUser.Address; //pokud se jedná o trenéra, je třeba smazat jeho termíny, které vede if (fitnessUser.Role.Name == "Trenér") { TermDao tDao = new TermDao(); IList <Term> terms = tDao.GetTermsByTrainer(fitnessUser); foreach (Term t in terms) { tDao.Delete(t); } }//pokud se jedna o zakaznika, je treba smazat rezervace, na ktere je zapsan else if (fitnessUser.Role.Name == "Zákazník") { ReservationDao rDao = new ReservationDao(); IList <Reservation> reservations = rDao.GetAllReservationsByUser(fitnessUser); foreach (Reservation r in reservations) { rDao.Delete(r); } } if (fitnessUser.SmallImageName != null) { System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + fitnessUser.SmallImageName)); } if (fitnessUser.BigImageName != null) { System.IO.File.Delete(Server.MapPath("~/Uploads/FitnessUser/" + fitnessUser.BigImageName)); } uDao.Delete(fitnessUser); aDao.Delete(address); TempData["succes"] = "Uživatelský účet byl odstraněn."; if (fitnessUser.Login == User.Identity.Name) { return(RedirectToAction("Logout", "Home")); } return(RedirectToAction("Index", "Home")); } catch (Exception e) { Console.WriteLine(e); throw; } }
public static object ApiPayRemoveAddress(IRequest context) { var addressId = context.GetPostInt("addressId"); AddressDao.Delete(addressId); return(new {}); }
public void IntegrationTest() { var connection = TestSession.GetConnection(); connection.Open(); #region good insertion and select by id test AddressModel inserted = new AddressModel(); inserted.AddressLine1 = TestSession.Random.RandomString(60); inserted.AddressLine2 = TestSession.Random.RandomString(60); inserted.City = TestSession.Random.RandomString(30); inserted.StateProvinceID = TestSession.Random.Next(); inserted.PostalCode = TestSession.Random.RandomString(15); inserted.SpatialLocation = TestSession.Random.RandomSqlGeography(); inserted.rowguid = Guid.NewGuid(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Insert(connection, new[] { inserted }); var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new AddressModelPrimaryKey() { AddressID = inserted.AddressID, }); CollectionAssert.IsNotEmpty(selectedAfterInsertion); var selectedAfterInsert = selectedAfterInsertion.Single(); Assert.AreEqual(inserted.AddressID, selectedAfterInsert.AddressID); Assert.AreEqual(inserted.AddressLine1, selectedAfterInsert.AddressLine1); Assert.AreEqual(inserted.AddressLine2, selectedAfterInsert.AddressLine2); Assert.AreEqual(inserted.City, selectedAfterInsert.City); Assert.AreEqual(inserted.StateProvinceID, selectedAfterInsert.StateProvinceID); Assert.AreEqual(inserted.PostalCode, selectedAfterInsert.PostalCode); Assert.AreEqual(inserted.SpatialLocation, selectedAfterInsert.SpatialLocation); Assert.AreEqual(inserted.rowguid, selectedAfterInsert.rowguid); Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate); #endregion #region update and select by id test inserted.AddressLine1 = TestSession.Random.RandomString(60); inserted.AddressLine2 = TestSession.Random.RandomString(60); inserted.City = TestSession.Random.RandomString(30); inserted.StateProvinceID = TestSession.Random.Next(); inserted.PostalCode = TestSession.Random.RandomString(15); inserted.SpatialLocation = TestSession.Random.RandomSqlGeography(); inserted.rowguid = Guid.NewGuid(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Update(connection, new[] { inserted }); var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new AddressModelPrimaryKey() { AddressID = inserted.AddressID, }); CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss); var selectedAfterUpdate = selectedAfterUpdateAddresss.Single(); Assert.AreEqual(inserted.AddressID, selectedAfterUpdate.AddressID); Assert.AreEqual(inserted.AddressLine1, selectedAfterUpdate.AddressLine1); Assert.AreEqual(inserted.AddressLine2, selectedAfterUpdate.AddressLine2); Assert.AreEqual(inserted.City, selectedAfterUpdate.City); Assert.AreEqual(inserted.StateProvinceID, selectedAfterUpdate.StateProvinceID); Assert.AreEqual(inserted.PostalCode, selectedAfterUpdate.PostalCode); Assert.AreEqual(inserted.SpatialLocation, selectedAfterUpdate.SpatialLocation); 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 AddressModelPrimaryKey() { AddressID = inserted.AddressID, }); CollectionAssert.IsEmpty(selectedAfterDeleteAddresss); #endregion connection.Close(); }