public void Dispose() { _firstUow.WarehouseRepository.Delete(_testEntityId); _firstUow.SaveChanges(); _firstUow.Dispose(); _secondUow.Dispose(); }
public ActionResult Ekle(tbl_Marka marka) { uow.MarkaRepository.Add(new tbl_Marka { Marka_Adi = marka.Marka_Adi }); uow.SaveChanges(); return(RedirectToAction("Liste")); }
public ActionResult Ekle(tbl_Kategori kat) { if (ModelState.IsValid) { uow.GetRepository <tbl_Kategori>().Add(kat); uow.SaveChanges(); return(RedirectToAction("Liste")); } return(View(kat)); }
public ActionResult Create([Bind(Include = "id,ad,kod,aciklama,adet")] tbl_Stok tbl_Stok) { if (ModelState.IsValid) { uow.GetRepository <tbl_Stok>().Add(tbl_Stok); uow.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_Stok)); }
public ActionResult Create([Bind(Include = "Id,Name,FamilyName,BirthDate,Address")] Person person) { if (ModelState.IsValid) { db.Persons.Add(person); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(person)); }
private void StokSil(Cart cart) { foreach (var cartline in cart.CartLines) { // int sayi = cartline.Adet; tbl_Urun satilanurun = new tbl_Urun(); satilanurun = cartline.Urun; satilanurun.Stok = satilanurun.Stok - cartline.Adet; var urun = uow.UrunRepository.Get(i => i.Urun_Id == satilanurun.Urun_Id); urun.Stok = satilanurun.Stok; uow.UrunRepository.Update(urun); uow.SaveChanges(); } }
public bool Update(CategoryModel entity) { try { using (StockDbContext context = new StockDbContext()) using (IUnitOfWork unitofwork = new EfUnitOfWork(context)) { var category = unitofwork.GetRepository <Category>().GetById(entity.CategoryId); category.CategoryName = entity.CategoryName; category.Description = entity.Description; unitofwork.GetRepository <Category>().Update(category); int saveCount = unitofwork.SaveChanges(); if (saveCount == 0) { return(false); } return(true); } } catch (Exception ex) { Console.WriteLine(ex); throw; } }
public ActionResult Index(tbl_Duyuru d, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file.ContentLength > 0 || file != null) { var extention = Path.GetExtension(file.FileName); if (extention == ".jpg" || extention == ".png") { var filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/upload"), filename); file.SaveAs(path); uow.GetRepository <tbl_Duyuru>().Update(new tbl_Duyuru { Duyuru_Id = d.Duyuru_Id, Link = d.Link, Mesaj = d.Mesaj, ResimURL = filename }); uow.SaveChanges(); return(View(d)); ViewBag.DuyuruGuncellendi = "Duyuru güncellendi."; } } } return(View(d)); }
void Session_Start(object sender, EventArgs e) { uow.GetRepository <Ziyaretci>().Add(new Ziyaretci { ZiyaretTarihi = DateTime.Now }); uow.SaveChanges(); }
public ActionResult Create([Bind(Include = "id,stokID,alinanAdet,tarih")] tbl_StokHareket tbl_StokHareket) { tbl_Stok stoktakiUrun = uow.GetRepository <tbl_Stok>().GetById((int)tbl_StokHareket.stokID); if (ModelState.IsValid && stoktakiUrun.adet > tbl_StokHareket.alinanAdet) { uow.GetRepository <tbl_StokHareket>().Add(tbl_StokHareket); uow.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.Hata = "Stokta Yeteri kadar ürün bulunmamaktadır"; } ViewBag.stokID = new SelectList(uow.GetRepository <tbl_Stok>().GetAll(), "id", "ad", tbl_StokHareket.stokID); return(View(tbl_StokHareket)); }
public ActionResult UrunIndirim(tbl_Urun urun, decimal indirim) { if (urun.Urun_Id != 0) { var IndirimYapilacakUrun = uow.UrunRepository.Get(x => x.Urun_Id == urun.Urun_Id); if (IndirimYapilacakUrun.Indirim_Oranı == 1) { IndirimYapilacakUrun.Indirim_Oranı += indirim; } else { IndirimYapilacakUrun.Indirim_Oranı += indirim; } uow.SaveChanges(); ViewBag.mesaj = "indirim işlemi tamamlandı"; } return(View("Index")); }
public ActionResult Ekle(tbl_Urun urun, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file.ContentLength > 0 || file != null) { var extention = Path.GetExtension(file.FileName); if (extention == ".jpg" || extention == ".png") { var filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/upload"), filename); file.SaveAs(path); uow.UrunRepository.Add(new tbl_Urun { Urun_Adi = urun.Urun_Adi, Fiyat = urun.Fiyat, Aciklama = urun.Aciklama, Kategori_ID = urun.Kategori_ID, Seri_No = urun.Seri_No, Marka_ID = urun.Marka_ID, Stok = urun.Stok, Resim_URL = file.FileName, Indirim_Oranı = 1 }); uow.GetRepository <tbl_Yildiz>().Add(new tbl_Yildiz { Urun_Id = urun.Urun_Id, Yildiz = 0 }); uow.SaveChanges(); return(RedirectToAction("Liste")); } } } ViewBag.Kategori_ID = new SelectList(uow.GetRepository <tbl_Kategori>().GetAll(), "Kategori_Id", "Kategori"); ViewBag.Marka_Id = new SelectList(uow.MarkaRepository.GetAll(), "Marka_Id", "Marka_Adi"); return(View(urun)); }
public void VerifyUnitOfWorkCallsContextSaveChanges() { // Arrange Mock <DbContext> mockContext = new Mock <DbContext>(); // Act EfUnitOfWork <DbContext> uow = new EfUnitOfWork <DbContext>(mockContext.Object); uow.SaveChanges(); // Assert mockContext.Verify(ctx => ctx.SaveChanges(), Times.Once); }
public ActionResult ProfiliDüzenle(tbl_Kullanici k) { uow.GetRepository <tbl_Kullanici>().Update(k); uow.SaveChanges(); if (HttpContext.User.Identity.Name != k.Kullanici_Adi) { return(RedirectToAction("Login", "Security")); } else { return(RedirectToAction("Profilim")); } }
public void VerifyDbUpdateConcurrencyException_TranslatedTo_DBConcurrencyException() { // Arrange Mock <DbContext> mockContext = new Mock <DbContext>(); mockContext.Setup(ctx => ctx.SaveChanges()) .Throws <DbUpdateConcurrencyException>(); // Act and Assert EfUnitOfWork <DbContext> uow = new EfUnitOfWork <DbContext>(mockContext.Object); var exception = Assert.Throws <DBConcurrencyException>(() => uow.SaveChanges()); exception.InnerException.Should().BeOfType <DbUpdateConcurrencyException>(); }
public bool Delete(Guid id) { using (StockDbContext context = new StockDbContext()) using (IUnitOfWork unitofwork = new EfUnitOfWork(context)) { unitofwork.GetRepository <Employee>().Delete(id); int saveCount = unitofwork.SaveChanges(); if (saveCount == 0) { return(false); } return(true); } }
public ActionResult Begen(int id) { var urun = uow.UrunRepository.GetById(id); var kullanici = HttpContext.User.Identity.Name; var begenen_kullanici = uow.GetRepository <tbl_Kullanici>().Get(x => x.Kullanici_Adi == kullanici); var favoriMi = uow.GetRepository <tbl_Favori>() .Get(x => x.Kullanici_ID == begenen_kullanici.Kullanici_Id && x.Urun_ID == id); if (favoriMi == null) { uow.GetRepository <tbl_Favori>().Add(new tbl_Favori { Kullanici_ID = begenen_kullanici.Kullanici_Id, Urun_ID = urun.Urun_Id }); } else { uow.GetRepository <tbl_Favori>().Delete(favoriMi.Favori_Id); } uow.SaveChanges(); return(View()); }
public bool Delete(EmployeeModel entity) { using (StockDbContext context = new StockDbContext()) using (IUnitOfWork unitOfWork = new EfUnitOfWork(context)) { Employee employee = StockMapper.EmployeeMap(entity); unitOfWork.GetRepository <Employee>().Delete(employee); int saveCount = unitOfWork.SaveChanges(); if (saveCount == 0) { return(false); } return(true); } }
public bool Delete(OrderModel entity) { using (StockDbContext context = new StockDbContext()) using (IUnitOfWork unitOfWork = new EfUnitOfWork(context)) { Order order = StockMapper.OrderMap(entity); unitOfWork.GetRepository <Order>().Delete(order); int saveCount = unitOfWork.SaveChanges(); if (saveCount == 0) { return(false); } return(true); } }
public ActionResult Uyeol(tbl_Kullanici kullanici) { uow.GetRepository <tbl_Kullanici>().Add(new tbl_Kullanici { Ad = kullanici.Ad, Soyad = kullanici.Soyad, Kullanici_Adi = kullanici.Kullanici_Adi, Sifre = kullanici.Sifre, Eposta = kullanici.Eposta, Telefon = kullanici.Telefon, UyeKayitTarihi = DateTime.Now, Rol_ID = 2 }); uow.SaveChanges(); return(RedirectToAction("Login", "Security")); }
public void AddProduct(tbl_Urun product, int adet) { var line = _cartlines.FirstOrDefault(i => i.Urun.Urun_Id == product.Urun_Id); if (line == null) { _cartlines.Add(new Cartline { Urun = product, Adet = adet }); } else { line.Adet += adet; } uow.GetRepository <tbl_Sepet>().Add(new tbl_Sepet { Urun_ID = product.Urun_Id, Adet = adet }); uow.SaveChanges(); //var varsa = uow.GetRepository<tbl_Satin_Alma>().Get(i => i.Urun_ID == product.Urun_Id); //if (varsa != null) //{ // tbl_Satin_Alma sa = new tbl_Satin_Alma(); // sa.Satis_Id = varsa.Satis_Id; // sa.Adet = varsa.Adet + adet; // sa.Urun_ID = varsa.Urun_ID; // // db.tbl_Satin_Alma.Attach(sa); // // db.Entry(sa).State = EntityState.Modified; // db.SaveChanges(); // // db.SaveChanges(); // uow.GetRepository<tbl_Satin_Alma>().Update(sa); // uow.SaveChanges(); //} //else //{ // } }
public EfUnitOfWorkTests() { _firstUow = new EfUnitOfWork(); _secondUow = new EfUnitOfWork(); var testEntity = new Warehouse { City = InitialCity, State = InitialState }; testEntity = _firstUow.WarehouseRepository.Create(testEntity); _firstUow.SaveChanges(); _testEntityId = testEntity.Id; }
public void DeleteAllForUserAndShoppingList_ShouldDeleteAllPermissions_ForTheGivenUserAndShoppingList() { var testDataKeys = CreateTestData(); using (var dbContext = TestUtils.CreateDbContext(_connection, new MockUserContext(testDataKeys.UserId))) using (IUnitOfWork unitOfWork = new EfUnitOfWork(dbContext)) { var permissionRepository = new PermissionRepository(dbContext); permissionRepository.DeleteAllForUserAndShoppingList(testDataKeys.ShoppingListId, testDataKeys.UserId); unitOfWork.SaveChanges(); } using (var dbContext = TestUtils.CreateDbContext(_connection, new MockUserContext(testDataKeys.UserId))) using (IUnitOfWork unitOfWork = new EfUnitOfWork(dbContext)) { var permissionRepository = new PermissionRepository(dbContext); var permissions = permissionRepository.FindAllForUserAndShoppingList(testDataKeys.UserId, testDataKeys.ShoppingListId); Assert.AreEqual(0, permissions.Count()); } }
public bool Delete(CustomerModel entity) { try { if (entity != null) { using (StockDbContext context = new StockDbContext()) using (IUnitOfWork unitofwork = new EfUnitOfWork(context)) { Customer customer = new Customer { CustomerId = Guid.NewGuid(), City = entity.City, CompanyName = entity.CompanyName, Address = entity.Address, Region = entity.Region, Phone = entity.Phone, ContactTitle = entity.ContactTitle, ContactName = entity.ContactName, PostalCode = entity.PostalCode, Country = entity.Country, Fax = entity.Fax, }; unitofwork.GetRepository <Customer>().Delete(customer); int saveCount = unitofwork.SaveChanges(); if (saveCount == 0) { return(false); } return(true); } } } catch (Exception ex) { Console.WriteLine(ex); throw; } return(true); }
public Model.Result.CustomerAddResult AddCustomer(CustomerAddRequest request) { CustomerAddResult result = new CustomerAddResult(); try { if (request != null && request.CustomerModel != null) { using (StockDbContext context = new StockDbContext()) using (IUnitOfWork unitofwork = new EfUnitOfWork(context)) { Customer customer = new Customer { CustomerId = Guid.NewGuid(), City = request.CustomerModel.City, CompanyName = request.CustomerModel.CompanyName, Address = request.CustomerModel.Address, Region = request.CustomerModel.Region, Phone = request.CustomerModel.Phone, ContactTitle = request.CustomerModel.ContactTitle, ContactName = request.CustomerModel.ContactName, PostalCode = request.CustomerModel.PostalCode, Country = request.CustomerModel.Country, Fax = request.CustomerModel.Fax, }; unitofwork.GetRepository <Customer>().Add(customer); result.SaveCount = unitofwork.SaveChanges(); if (result.SaveCount > 0) { return(result); } } } } catch (Exception ex) { Console.WriteLine(ex); throw; } return(result); }
public void AddTaskTest() { DbConnection connection = Effort.DbConnectionFactory.CreateTransient(); EfUnitOfWork efUnitOfWork = new EfUnitOfWork(connection); efUnitOfWork.Jobs.Add(new Job() { Date = DateTime.Now, Task = "1", Repeat = 1, Name = "1", Settings = "1", Param = "1", StopResult = "1", ErrorResult = "1" }); efUnitOfWork.SaveChanges(); Assert.AreEqual(efUnitOfWork.Jobs.Count(), 1); }
TestMethodProductAdd() { using (StockDbContext context = new StockDbContext()) using (IUnitOfWork unitofwork = new EfUnitOfWork(context)) { Product product = new Product() { ProductId = Guid.NewGuid(), Discontinued = true, ProductName = "At", SupplierId = Guid.NewGuid(), CategoryId = Guid.NewGuid(), UnitPrice = 5, UnitsInStock = 15, QuantityPerUnit = "kestanesi", }; unitofwork.GetRepository <Product>().Add(product); unitofwork.SaveChanges(); } }
public void OnlyStoreWinsStrategy_Works() { var firstEntityCopy = _firstUow.WarehouseRepository.ReadOne(_testEntityId); var secondEntityCopy = _secondUow.WarehouseRepository.ReadOne(_testEntityId); firstEntityCopy.City = "Changed City"; secondEntityCopy.State = "Changed State"; _firstUow.WarehouseRepository.Update(firstEntityCopy); _secondUow.WarehouseRepository.Update(secondEntityCopy); _firstUow.SaveChanges(); Assert.Throws <InvalidOperationException>(() => { _secondUow.SaveChanges(); }); firstEntityCopy = _firstUow.WarehouseRepository.ReadOne(_testEntityId); Assert.Equal(InitialState, firstEntityCopy.State); }
public bool Delete(Guid id) { try { using (StockDbContext context = new StockDbContext()) using (IUnitOfWork unitofwork = new EfUnitOfWork(context)) { unitofwork.GetRepository <Customer>().Delete(id); int savecount = unitofwork.SaveChanges(); if (savecount == 0) { return(false); } return(true); } } catch (Exception ex) { Console.WriteLine(ex); throw; } }
public bool Delete(CategoryModel entity) { try { using (StockDbContext context = new StockDbContext()) using (IUnitOfWork unitofwork = new EfUnitOfWork(context)) { Category category = StockMapper.CategoryMap(entity); unitofwork.GetRepository <Category>().Delete(category); int saveCount = unitofwork.SaveChanges(); if (saveCount == 0) { return(false); } return(true); } } catch (Exception ex) { Console.WriteLine(ex); throw; } }