private void NewBill_Load(object sender, EventArgs e) { var genericRepositoryTip = new GenericRepository <FaturaTip>(new OtoContext()); genericRepositoryTip.Create(new FaturaTip() { faturatipNo = 0, faturaTuru = "Alım işlemi" }); genericRepositoryTip.Create(new FaturaTip() { faturatipNo = 1, faturaTuru = "Satım işlemi" }); comboBoxFaturatip.DataSource = genericRepositoryTip.GetAll().ToList(); comboBoxFaturatip.DisplayMember = "faturaTuru"; comboBoxFaturatip.ValueMember = "faturatipNo"; comboBoxUrun.Items.Add("Deneme"); /*var genericRepositoryUrun = new GenericRepository<Stok>(new OtoContext()); * comboBoxUrun.DataSource = genericRepositoryUrun.GetAll().ToList(); * comboBoxUrun.DisplayMember = "UrunId"; * comboBoxUrun.ValueMember = "UrunId";*/ int[] sayilar = new int[50]; for (int i = 1; i <= 50; i++) { sayilar[i - 1] = i; } comboBoxUrunadet.DataSource = sayilar; }
private void NewStock_Load(object sender, EventArgs e) { var grUrunDetay = new GenericRepository <UrunDetay>(new OtoContext()); grUrunDetay.Create(new UrunDetay() { UrunMarka = "Mercedes", UrunModel = "Mercedes Ayna", UrunUretimTarihi = DateTime.Now }); grUrunDetay.Create(new UrunDetay() { UrunMarka = "Mercedes", UrunModel = "Mercedes boya", UrunUretimTarihi = DateTime.Now }); /* * comboBoxUrunmarka.DataSource = grUrunDetay.GetAll().Where(i=>i.UrunDetayId==).ToList(); * comboBoxUrunmarka.DisplayMember = "UrunMarka"; * comboBoxUrunmarka.ValueMember = "UrunDetayId"; */ comboBoxUrunmodel.DataSource = grUrunDetay.GetAll().ToList(); comboBoxUrunmodel.DisplayMember = "UrunModel"; comboBoxUrunmodel.ValueMember = "UrunDetayId"; comboBoxBirim.Items.Add("Adet"); comboBoxBirim.Items.Add("Kg"); FillGrid(); }
public void Handle(MoneyTransferedEvent @event) { var notification = new TblNotifications { IsDisplayed = false, Login = _loginRepository.GetById(@event.AccountId), Message = string.Format($"{@event.Amount} transfered: {@event.OccurredOn}.") }; _notificationRepository.Create(notification); }
public void AddTodo(Todo task) { task.Id = repo.CreateId(); repo.Create(task); if (task.Notify == 1) { task.CreateNotification(); } if (task.Notify == 2) { task.CreateAlarm(); } }
public int Create(RecipeBL recipe, List <CategoryRecipeBL> listOfCategories, List <SubcategoryRecipeBL> listOfSubcategories) { RatingService r = new RatingService(); var ratingID = r.CreateEmptyRating(); var recipeDAL = new Recipe() { Name = recipe.Name, Description = recipe.Description, LongDescription = recipe.LongDescription, RatingID = ratingID, PictureLocation = recipe.PictureLocation, PrepTime = recipe.PrepTime, CookTime = recipe.CookTime }; int id = recipeRepository.Create(recipeDAL); List <CategoryRecipe> categoriesRecipe = new List <CategoryRecipe>(); List <SubcategoryRecipe> subcategoriesRecipe = new List <SubcategoryRecipe>(); foreach (var c in listOfCategories) { categoriesRecipe.Add(new CategoryRecipe { CategoryID = c.CategoryID, RecipeID = id }); } foreach (var c in categoriesRecipe) { categoryRecipeRepository.Create(c); } foreach (var s in listOfSubcategories) { subcategoriesRecipe.Add(new SubcategoryRecipe { SubcategoryID = s.SubcategoryID, RecipeID = id }); } foreach (var s in subcategoriesRecipe) { subcategoryRecipeRepository.Create(s); } return(id); }
public ActionResult <Job> PostJob(NewJob newJob) { var job = _mapper.Map <EfJob>(newJob); _jobRepository.Create(job); return(_mapper.Map <Job>(job)); }
public ActionResult Create(Product product) { ViewBag.CategoryId = new SelectList(_category.GetAll(), "Id", "Name"); ViewBag.TypeAttribute = _typeAttribute.GetAll().AsQueryable().Include(x => x.Attributes).AsEnumerable(); if (ModelState.IsValid) { var user = Session["User"] as User; if (product.ProductAttributes != null) { foreach (var item in product.ProductAttributes) { item.ProductId = product.Id; } } product.UpdateAt = DateTime.Now; product.UpdateBy = user.Email; product.CreateAt = DateTime.Now; product.CreateBy = user.Id; product.Status = true; product.Reate = 5; product.CountBuy = 0; product.CountView = 0; if (_product.Create(product)) { TempData["CreateSuccess"] = "Create Success"; return(RedirectToAction("Index")); } else { TempData["CreateFalse"] = "Create False!"; return(View(product)); } } return(View(product)); }
public void AddPlatform() { contextMock = new Mock <GameStoreDbContext>(); Mock <DbSet <Platform> > entitiesMock; entitiesMock = new Mock <DbSet <Platform> >(); contextMock.Setup(x => x.Set <Platform>()).Returns(entitiesMock.Object); entitiesMock.Setup(x => x.Find(It.IsAny <object>())).Returns(new Platform { Id = 1, Games = new List <Game>(), Type = "type" }); GenericRepository <Platform> genericRepository = new GenericRepository <Platform>(contextMock.Object); var platform = new Platform() { Id = 1, Games = new List <Game>(), Type = "type" }; genericRepository.Create(platform); entitiesMock.Verify(x => x.Add(platform), Times.Once); }
public void AddGenre() { contextMock = new Mock <GameStoreDbContext>(); Mock <DbSet <Genre> > entitiesMock; entitiesMock = new Mock <DbSet <Genre> >(); contextMock.Setup(x => x.Set <Genre>()).Returns(entitiesMock.Object); entitiesMock.Setup(x => x.Find(It.IsAny <object>())).Returns(new Genre { Id = 1, Games = new List <Game>(), Name = "54574" }); GenericRepository <Genre> genericRepository = new GenericRepository <Genre>(contextMock.Object); var genre = new Genre { Id = 1, Games = new List <Game>(), Name = "54574" }; genericRepository.Create(genre); entitiesMock.Verify(x => x.Add(genre), Times.Once); }
public ResultModel AddAbonentClaim(int readerId, int libId) { ResultModel result = new ResultModel(); try { GenericRepository <AbonentLists> generic = new GenericRepository <AbonentLists>(_context); AbonentLists abonent = new AbonentLists { AbonentStatus = 1, Library = libId, Reader = readerId, ReaderCard = ReaderCardGenerator.Generate(readerId, libId) }; generic.Create(abonent); result.Message = "Ваша заявка принята к рассмотрению."; } catch (Exception exc) { result.Code = OperationStatusEnum.UnexpectedError; result.Message = exc.Message; } return(result); }
public static void Initialize() { DbConnection connection = Effort.DbConnectionFactory.CreateTransient(); dbContext = new NForumDbContext(connection); DataStore = new NForum.Database.EntityFramework.EntityFrameworkDataStore( new GenericRepository <NForum.Database.EntityFramework.Dbos.Category>(dbContext), new GenericRepository <NForum.Database.EntityFramework.Dbos.Forum>(dbContext), new GenericRepository <NForum.Database.EntityFramework.Dbos.Topic>(dbContext), new GenericRepository <NForum.Database.EntityFramework.Dbos.Reply>(dbContext), new GenericRepository <NForum.Database.EntityFramework.Dbos.ForumUser>(dbContext) ); GenericRepository <NForum.Database.EntityFramework.Dbos.ForumUser> fuRepo = new GenericRepository <Database.EntityFramework.Dbos.ForumUser>(dbContext); NForum.Database.EntityFramework.Dbos.ForumUser fu = fuRepo.Create(new Database.EntityFramework.Dbos.ForumUser { Deleted = false, EmailAddress = "*****@*****.**", ExternalId = "todo", Fullname = "mrfake", Username = "******", UseFullname = true }); PermissionService = new PermissionService(); LoggingService = new LoggingService(new FakeLogger(), new FakeLogger()); UserProvider = new FakeUserProvider(fu); EventPublisher = new FakeEventPublisher(); CategoryService = new CategoryService(DataStore, PermissionService, LoggingService, UserProvider, EventPublisher); ForumService = new ForumService(DataStore, PermissionService, LoggingService, UserProvider, EventPublisher); TopicService = new TopicService(DataStore, PermissionService, LoggingService, UserProvider, EventPublisher); UIService = new UIService(DataStore, PermissionService, LoggingService, UserProvider, new FakeSettings()); }
public ActionResult Register(RegisterViewModel registerViewModel) { if (ModelState.IsValid) { User user = new User(); user.Email = registerViewModel.Email; user.Password = registerViewModel.Password; user.FullName = registerViewModel.FullName; user.BirthDay = registerViewModel.BirthDay; user.PhoneNumber = registerViewModel.PhoneNumber; user.Address = registerViewModel.Address; user.CreateAt = DateTime.Now; user.UpdateAt = DateTime.Now; user.GroupId = 2; user.Status = true; if (_repositoryUser.GetAll().FirstOrDefault(x => x.Email == user.Email) != null) { ModelState.AddModelError("Email", "Email already exists"); return(View(registerViewModel)); } if (_repositoryUser.Create(user)) { Helper.SendMail(user.Email, "*****@*****.**", "Anhquang1009", "QTShop_Đăng ký tài khoản", string.Format(@" <h1> Đăng ký tài khoản thành công</h1> <b>Email đăng ký :</b> {0} <p>Visit: https://localhost:44341</p> <p>Trân trọng </p> ", user.Email)); TempData["RigisterSucess"] = "Register successfully!"; return(RedirectToAction("Login")); } return(View(registerViewModel)); } return(View(registerViewModel)); }
public ActionResult <Model> PostModel(ModelDetails modelDto) { if (modelDto == null) { throw new ArgumentNullException(nameof(modelDto)); } modelDto.Email = modelDto.Email.ToLower(CultureInfo.CurrentCulture); var emailExist = _modelRepository.GetBy(selector: source => source, predicate: u => u.Email == modelDto.Email).FirstOrDefault(); if (emailExist != null) { ModelState.AddModelError("Email", "Email already in use"); return(BadRequest(ModelState)); } var model = _mapper.Map <EfModel>(modelDto); var account = new EfAccount() { Email = model.Email, IsManager = false, PwHash = HashPassword(modelDto.Password, _appSettings.BcryptWorkfactor) }; _accountRepository.Create(account); model.Account = _accountRepository.GetBy(source => source, a => a.Email == account.Email, disableTracking: false).FirstOrDefault(); _modelRepository.Create(model); return(_mapper.Map <Model>(model)); }
public Booking RentACar(CarCategory carCategory, DateTime customerBirthDate, DateTime dateOfRentalStart, DateTime dateOfRentalEnd) { var availableCars = GetAvailableCars(carCategory, dateOfRentalStart, dateOfRentalEnd); if (!availableCars.Any()) { throw new DBItemNotFoundException("There were no available cars in the database for the specified car category and reservation dates."); } var chosenCar = availableCars.First(); if (dateOfRentalEnd < dateOfRentalStart) { throw new DateOutOfRangeException("ReturnDate for the car can not be before startdate of the booking/reservation."); } var newBooking = new Booking { Car = chosenCar, CustomerBirthDate = customerBirthDate, RentalDate = dateOfRentalStart, DateOfRentalEnd = dateOfRentalEnd, }; repos.Create(newBooking); repos.SaveChanges(); return(newBooking); }
public ActionResult Create(Group group) { if (ModelState.IsValid) { var user = Session["User"] as User; group.CreateAt = DateTime.Now; group.Status = true; group.CreateBy = user.Id; if (_group.GetAll().FirstOrDefault(x => x.GroupName == group.GroupName) != null) { ModelState.AddModelError("TypeName", "Category already exists"); return(View(group)); } try { if (_group.Create(group)) { TempData["CreateSuccess"] = "Create Success"; return(RedirectToAction("Index")); } else { return(View(group)); } } catch (Exception) { return(View(group)); } } return(View()); }
public ResultModel Add(AuthorDTO model) { ResultModel result = new ResultModel(); if (model != null) { try { repository.Create((Authors)model); result.Message = "Данные успешно добавлены"; } catch (Exception ex) { result.Code = OperationStatusEnum.UnexpectedError; result.Message = ex.Message; } } else { result.Code = OperationStatusEnum.UnexpectedError; result.Message = "Ошибка при добавлении данных"; } return(result); }
public void CreateOrderDetails_CallsAddMethod() { Mock <GameStoreDbContext> contextMock = new Mock <GameStoreDbContext>(); Mock <DbSet <OrderDetails> > entitiesMock = new Mock <DbSet <OrderDetails> >(); contextMock.Setup(x => x.Set <OrderDetails>()).Returns(entitiesMock.Object); entitiesMock.Setup(x => x.Add(It.IsAny <OrderDetails>())); GenericRepository <OrderDetails> genericRepository = new GenericRepository <OrderDetails>(contextMock.Object); var item = new OrderDetails { Game = new Game(), Order = new Order(), Id = 1, IsDeleted = true, Price = 0.01m, Discount = 0.01f, GameId = 1, OrderId = 1, Quantity = 10 }; genericRepository.Create(item); entitiesMock.Verify(x => x.Add(item), Times.Once); }
public void EntrarNaEstacao(CartaoViagem cartaoViagem, DateTime data, Zona zona) { if (cartaoViagem.Tarifa.Zona == Zona.A && zona == Zona.B) { throw new Exception("zona_cartao_invalida"); } else if (cartaoViagem.Status == StatusCartaoViagem.Consumido) { throw new Exception("cartao_invalido"); } else { cartaoViagem.DataVigente = (cartaoViagem.Status == StatusCartaoViagem.Pendente) ? data : cartaoViagem.DataVigente; var viagem = new Viagem() { DataEntrada = data, Zona = zona }; _viagemRepository.Create(viagem); _viagemRepository.Commit(); cartaoViagem.Viagens.Add(viagem); if (cartaoViagem.Status == StatusCartaoViagem.Pendente) { var contaBancaria = _contaBancariaRepository.Read().Where(c => c.Proprietario == cartaoViagem.Proprietario).FirstOrDefault(); CobrarDaContaBancaria(contaBancaria, cartaoViagem.Tarifa.Valor); cartaoViagem.Status = StatusCartaoViagem.Pago; } _cartaoViagemRepository.Update(cartaoViagem); _cartaoViagemRepository.Commit(); } }
public void CreateGame_CallsAddMethod() { Mock <GameStoreDbContext> contextMock = new Mock <GameStoreDbContext>(); Mock <DbSet <Game> > entitiesMock = new Mock <DbSet <Game> >(); contextMock.Setup(x => x.Set <Game>()).Returns(entitiesMock.Object); entitiesMock.Setup(x => x.Add(It.IsAny <Game>())); GenericRepository <Game> genericRepository = new GenericRepository <Game>(contextMock.Object); var game = new Game { Name = "", Key = "", Genres = new List <Genre>(), Publishers = new List <Publisher>(), Platforms = new List <Platform>(), IsDeleted = false, Comments = new List <Comment>(), UnitsInStock = 12, Id = 1, Description = "", Price = 123, Discontinued = true }; genericRepository.Create(game); entitiesMock.Verify(x => x.Add(game), Times.Once); }
public ActionResult UpdatePermission(GroupRole groupRole) { // kiểm tra quền đã được gán hay chưa if (_groupRole.GetAll().Any(x => x.GroupId == groupRole.GroupId && x.BusinessId == groupRole.BusinessId && x.RoleId == groupRole.RoleId)) { // nếu có thì xóa (hủy quên) // lấy đối tượng cần xóa var obj = _groupRole.GetAll().FirstOrDefault(x => x.GroupId == groupRole.GroupId && x.BusinessId == groupRole.BusinessId && x.RoleId == groupRole.RoleId); _groupRole.DeleteEntity(obj); return(Json(new { Status = 200, Message = "Successfully canceled" }, JsonRequestBehavior.AllowGet));; } else { _groupRole.Create(groupRole); return(Json(new { Status = 200, Message = "Successful assignment" }, JsonRequestBehavior.AllowGet)); } }
//[Authorize(Roles = "Manager")] public ActionResult <Job> AddModelToJob(long jobId, long modelId) { var job = _jobRepository.GetBy(selector: source => source, predicate: j => j.EfJobId == jobId, disableTracking: false).FirstOrDefault(); if (job == null) { ModelState.AddModelError("jobId", "jobId not found"); return(BadRequest(ModelState)); } var model = _modelRepository.GetBy(selector: source => source, m => m.EfModelId == modelId, disableTracking: false).FirstOrDefault(); if (model == null) { ModelState.AddModelError("modelId", "modelId not found"); return(BadRequest(ModelState)); } _jobModelRepository.Create(new EfJobModel { Job = job, Model = model }); var updatedJob = _jobRepository.GetBy( selector: source => source, predicate: ej => ej.EfJobId == job.EfJobId, include: iq => iq.Include(ej => ej.JobModels) .ThenInclude(jm => jm.Model)).FirstOrDefault(); return(_mapper.Map <Job>(updatedJob)); }
public void Test_Create_Product_Warehouse() { var fakeContext = new FakeContext("Create_Products_Warehouse"); fakeContext.FillWith <Product>(); using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object)) { var fakeProduct = new Product(); fakeProduct.Sku = "3000"; fakeProduct.Name = "Product test"; fakeProduct.Price = 120M; fakeProduct.Quantity = 100; fakeProduct.CreatedAt = new DateTime(2020, 02, 22); fakeProduct.UpdatedAt = new DateTime(2020, 08, 15); var repository = new GenericRepository <Product>(context); repository.Create(fakeProduct); var createdProduct = repository.GetById(6); Assert.IsType <Product>(createdProduct); Assert.NotEqual(0, createdProduct.Id); Assert.Equal("Product test", createdProduct.Name); Assert.Equal("3000", createdProduct.Sku); Assert.Equal(120M, createdProduct.Price); Assert.Equal(100, createdProduct.Quantity); Assert.Equal(new DateTime(2020, 02, 22), createdProduct.CreatedAt); Assert.Equal(new DateTime(2020, 08, 15), createdProduct.UpdatedAt); Assert.Equal(6, createdProduct.Id); } }
public List <BodyBasicIndex> Add(BodyBasicIndex_VM _VM) { GenericRepository _repository = new GenericRepository(); BodyBasicIndex model = new BodyBasicIndex() { ID = _VM.ID, BMI = _VM.BMI, Date = _VM.Date, BodyFat = _VM.BodyFat, Height = _repository.GetT(_VM.ID).Height, SkeletalMuscleRate = _VM.SkeletalMuscleRate, VisceralFat = _VM.VisceralFat, Weight = _VM.Weight }; _repository.Create(model); List <BodyBasicIndex> result = new List <BodyBasicIndex>(); result.Add(_repository.GetT(model.ID, model.Date)); return(result); }
public void Handle(MoneyTransferedEvent @event) { var serializedEvent = JsonConvert.SerializeObject(@event); _eventRepository.Create(new TblEvents { JSON = serializedEvent }); }
private void AdcionarProprietarioComUmCartaoTaxaUnicaZonaA(out CartaoViagem cartaoViagem, out ContaBancaria contaBancaria) { var proprietario = new Proprietario("Igor Silva"); _proprietarioRepository.Create(proprietario); _proprietarioRepository.Commit(); var tarifa = _tarifaRepository.Read().Where(t => t.Jornada == Jornada.Unica && t.Zona == Zona.A).First(); cartaoViagem = new CartaoViagem(proprietario, tarifa); _cartaoViagemRepository.Create(cartaoViagem); _cartaoViagemRepository.Commit(); contaBancaria = new ContaBancaria("111111111111111", proprietario); _contaBancariaRepository.Create(contaBancaria); _contaBancariaRepository.Commit(); }
public ActionResult Register(RegisterModel registerModel) { ViewBag.UserName = AuthenticationManager.User.Identity.Name; var inventors = new GenericRepository <Inventor>(); inventors.Create(registerModel.ToInventor()); return(RedirectToAction("Login", "Account")); }
public ActionResult MesajYaz(Mesaj mesaj) { int a = mesaj.UrunId; mesaj.Gonderen = db.Urunlers.Where(x => x.UrunId == a).Select(x => x.UserID).SingleOrDefault(); mesaj.MesajTarihi = DateTime.Now; return(View(TempData["msg"] = msg.Create(mesaj) ? "Mesajınız iletildi.. " : "Hata ! Lütfen tekrar deneyiniz ...")); }
public void CreateItems() { for (int i = 0; i < 300; i++) { var nx = r.Next(100); repo.Create(new Dog() { Age = nx }); } for (int i = 0; i < 100; i++) { repo.Create(new Dog() { Age = i }); } }
public virtual int Create(M model) { //using (var scope = _context) //{ _repo.Create(model); _repo.Save(); return(model.Id); //} }
public ActionResult Kontrol(FormCollection c) { if (Session["user"] is User kullanici) { Urunler u = new Urunler(); u.Aciklama = ((Urunler)Session["urun"]).Aciklama.ToString(); u.AltLimit = ((Urunler)Session["urun"]).AltLimit; u.Bakilma = 0; u.Baslik = ((Urunler)Session["urun"]).Baslik.ToString(); u.DurumId = ((Urunler)Session["urun"]).DurumId; u.KategoriId = ((Urunler)Session["urun"]).KategoriId; u.UrunOlusturma = DateTime.Now; u.UserID = kullanici.UserID; u.Yayın = true; var ur = urn.Create(u); var menu = Session["res"] as List <Resimler>; foreach (var item in menu) { Resimler rs = new Resimler(); rs.ImageUrl = item.ImageUrl; rs.Resim = item.Resim; rs.UrunId = u.UrunId; rsm.Create(rs); } string img = Session["anagorsel"].ToString(); int lst = db.Resimlers.Where(x => x.ImageUrl == img).Select(x => x.ResimId).Single(); AnaGorsel ana = new AnaGorsel(); ana.ResimId = lst; db.AnaGorsels.Add(ana); db.SaveChanges(); u.GorselId = ana.GorselId; TempData["msg"] = urn.Edit(u) ? "Ürününüz Yayında" : "Hata !! Lütfen Tekrar Deneyiniz..."; return(RedirectToAction("Index", "Kullanici")); } return(View()); }