Esempio n. 1
0
        public void GivenAccount_WhenUpdate_ThenReturnUpdated()
        {
            var uow = new UoW(_chatContext);

            using (var dbContextTransaction = uow.BeginTransaction())
            {
                try
                {
                    //ARRANGE
                    string  newPassword = "******";
                    Account account     = AccountMother.NewAccount();
                    _accountRepository.Add(account);
                    uow.SaveChanges();

                    //ACT
                    var attachedAccount = _accountRepository.Get(account.AccountID);
                    attachedAccount.Password = newPassword;
                    uow.SaveChanges();

                    //ASSERT
                    var updatedAccount = _accountRepository.Get(account.AccountID);
                    Assert.NotNull(updatedAccount);
                    Assert.Equal(updatedAccount.Password, newPassword);
                }
                finally
                {
                    dbContextTransaction.Rollback();
                }
            }
        }
Esempio n. 2
0
        public void GivenNewAccount_WhenInsert_ThenReturnNotNull()
        {
            var uow = new UoW(_chatContext);

            using (var dbContextTransaction = uow.BeginTransaction())
            {
                try
                {
                    //ARRANGE
                    Account account = AccountMother.NewAccount();
                    _accountRepository.Add(account);

                    //ACT
                    uow.SaveChanges();

                    //ASSERT
                    var insertedAccount = _accountRepository.Get(account.AccountID);
                    Assert.NotNull(insertedAccount);
                    Assert.Equal(insertedAccount.Password, account.Password);
                }
                finally
                {
                    dbContextTransaction.Rollback();
                }
            }
        }
Esempio n. 3
0
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Company,Email,City,Postal,Street,Country,CreatorId,ModificationDate,CreationDate")] Customer customer)
 {
     Log.Debug("POST/Edit");
     if (ModelState.IsValid)
     {
         using (var uow = new UoW()){
             var customersRepo  = uow.GetRepository <ICustomerRepository>();
             var customermodify = customersRepo.GetByKey(customer.Id);
             customermodify.FirstName = customer.LastName;
             customermodify.LastName  = customer.LastName;
             customermodify.Company   = customer.Company;
             customermodify.Email     = customer.Email;
             customermodify.Street    = customer.Street;
             customermodify.Postal    = customer.Postal;
             customermodify.Country   = customer.Country;
             customermodify.City      = customer.City;
             customersRepo.Update(customermodify);
             uow.SaveChanges();
             return(RedirectToAction("Details", new { @id = customer.Id }));
         }
     }
     using (var uow = new UoW()){
         //ViewBag.CreatorId = new SelectList(uow.IdentityUsers.GetAll(), "Id", "UserName");
     }
     return(View(customer));
 }
Esempio n. 4
0
        protected override int SaveChanges()
        {
            var result1 = UoW.SaveChanges();
            var result2 = juridicoUoW.SaveChanges();

            return(result1 + result2);
        }
Esempio n. 5
0
 public ActionResult DeleteConfirmed(int id)
 {
     Log.Debug("POST/DeleteConfirmed Id:{0}", id.ToString());
     using (var uow = new UoW()){
         var customersRepo = uow.GetRepository <ICustomerRepository>();
         var customer      = customersRepo.GetByKey((System.Int32)id);
         customersRepo.Delete(customer);
         uow.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 6
0
        public override async Task <CreateAuthorResponse> Handle(CreateAuthorRequest request)
        {
            var response = new CreateAuthorResponse();
            var author   = MapFromRequestToEntity(request);
            await UoW.AuthorRepository.Create(author);

            await UoW.SaveChanges();

            response.Response = Enums.Responses.eResponseType.Ok;
            return(response);
        }
 public ActionResult DeleteConfirmed(int id)
 {
     Log.Debug("POST/DeleteConfirmed Id:{0}", id.ToString());
     using (var uow = new UoW())
     {
         var licensesRepo = uow.GetRepository <ILicensePocoRepository>();
         var licensepoco  = licensesRepo.GetByKey((System.Int32)id);
         licensesRepo.Delete(licensepoco);
         uow.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Create([Bind(Include = "Id,Name,PassPhrase,PrivateKey,PublicKey,CreationDate,CreatorId")] Product product)
 {
     Log.Debug("POST/Create");
     if (ModelState.IsValid)
     {
         using (var uow = new UoW())
         {
             var productsRepo = uow.GetRepository <IProductRepository>();
             _licenseGenerationService.GeneratePassPhraseForProduct(product);
             _licenseGenerationService.GenerateKeysForProduct(product);
             productsRepo.Add(product);
             uow.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
 public ActionResult Edit([Bind(Include = "Id,Name,PassPhrase,PrivateKey,PublicKey,CreationDate,CreatorId")] Product product)
 {
     Log.Debug("POST/Edit");
     if (ModelState.IsValid)
     {
         using (var uow = new UoW())
         {
             var productsRepo  = uow.GetRepository <IProductRepository>();
             var modifyproduct = productsRepo.GetByKey(product.Id);
             modifyproduct.Name = product.Name;
             productsRepo.Update(modifyproduct);
             uow.SaveChanges();
             return(RedirectToAction("Details", new { @id = product.Id }));
         }
     }
     return(View(product));
 }
Esempio n. 10
0
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Company,Email,City,Postal,Street,Country,CreatorId,ModificationDate,CreationDate")] Customer customer)
        {
            Log.Debug("POST/Create");
            if (ModelState.IsValid)
            {
                using (var uow = new UoW()){
                    var customersRepo = uow.GetRepository <ICustomerRepository>();
                    customersRepo.Add(customer);
                    uow.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }

            using (var uow = new UoW()){
                //ViewBag.CreatorId = new SelectList(uow.IdentityUsers.GetAll(), "Id", "UserName");
            }
            return(View(customer));
        }
Esempio n. 11
0
        public ActionResult Create([Bind(Include = "Id,Value,ExpireVersion,ExpireDate,CustomerId,ProductId,CreatorId,ModificationDate,CreationDate")] LicensePoco licensepoco)
        {
            Log.Debug("POST/Create");
            if (ModelState.IsValid)
            {
                _licenseGenerationService.GenerateLicenseValue(licensepoco);
                using (var uow = new UoW())
                {
                    var licensesRepo = uow.GetRepository <ILicensePocoRepository>();
                    licensesRepo.Add(licensepoco);
                    uow.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }

            using (var uow = new UoW())
            {
                ViewBag.CustomerId = JsonConvert.SerializeObject(uow.Customers.GetAll().ToList()); // new SelectList(uow.Customers.GetAll().ToList(), "Id", "FirstName");
                ViewBag.ProductId  = JsonConvert.SerializeObject(uow.Products.GetAll().ToList());  //new SelectList(uow.Products.GetAll().ToList(), "Id", "Name");
            }
            return(View(licensepoco));
        }
Esempio n. 12
0
        public Account AddAccount(Account account, string email)
        {
            //todo Add  businnes logic for new account
            var uow = new UoW(_chatContext);

            using (var dbContextTransaction = uow.BeginTransaction())
            {
                try
                {
                    _accountRepository.Add(account);
                    uow.SaveChanges();
                    _sendEmail.Send("from", email, "message");
                    _logData.LogThis(DateTime.Now + " insert " + account.AccountID);
                    dbContextTransaction.Commit();
                }
                catch (Exception ex)
                {
                    //todo some logs
                    dbContextTransaction.Rollback();
                    throw;
                }
            }
            return(account);
        }
 public ActionResult Create([Bind(Include = "Id,Name,PassPhrase,PrivateKey,PublicKey,CreationDate,CreatorId")] Product product)
 {
     Log.Debug("POST/Create");
     if (ModelState.IsValid)
     {
         using (var uow = new UoW())
         {
             var productsRepo = uow.GetRepository<IProductRepository>();
             _licenseGenerationService.GeneratePassPhraseForProduct(product);
             _licenseGenerationService.GenerateKeysForProduct(product);
             productsRepo.Add(product);
             uow.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     return View(product);
 }
 public ActionResult DeleteConfirmed(int id)
 {
     Log.Debug("POST/DeleteConfirmed Id:{0}", id.ToString());
     using (var uow = new UoW())
     {
         var licensesRepo = uow.GetRepository<ILicensePocoRepository>();
         var licensepoco = licensesRepo.GetByKey((System.Int32) id);
         licensesRepo.Delete(licensepoco);
         uow.SaveChanges();
     }
     return RedirectToAction("Index");
 }
        public ActionResult Create([Bind(Include = "Id,Value,ExpireVersion,ExpireDate,CustomerId,ProductId,CreatorId,ModificationDate,CreationDate")] LicensePoco licensepoco)
        {
            Log.Debug("POST/Create");
            if (ModelState.IsValid)
            {
                _licenseGenerationService.GenerateLicenseValue(licensepoco);
                using (var uow = new UoW())
                {
                    var licensesRepo = uow.GetRepository<ILicensePocoRepository>();
                    licensesRepo.Add(licensepoco);
                    uow.SaveChanges();
                }
                return RedirectToAction("Index");
            }

            using (var uow = new UoW())
            {
                ViewBag.CustomerId = JsonConvert.SerializeObject(uow.Customers.GetAll().ToList()); // new SelectList(uow.Customers.GetAll().ToList(), "Id", "FirstName");
                ViewBag.ProductId = JsonConvert.SerializeObject(uow.Products.GetAll().ToList());//new SelectList(uow.Products.GetAll().ToList(), "Id", "Name");
            }
            return View(licensepoco);
        }
 public ActionResult Edit([Bind(Include = "Id,Name,PassPhrase,PrivateKey,PublicKey,CreationDate,CreatorId")] Product product)
 {
     Log.Debug("POST/Edit");
     if (ModelState.IsValid)
     {
         using (var uow = new UoW())
         {
             var productsRepo = uow.GetRepository<IProductRepository>();
             var modifyproduct = productsRepo.GetByKey(product.Id);
             modifyproduct.Name = product.Name;
             productsRepo.Update(modifyproduct);
             uow.SaveChanges();
             return RedirectToAction("Details", new { @id = product.Id});
         }
     }
     return View(product);
 }
 public ActionResult DeleteConfirmed(int id)
 {
     Log.Debug("POST/DeleteConfirmed Id:{0}", id.ToString());
     using (var uow = new UoW())
     {
         var productsRepo = uow.GetRepository<IProductRepository>();
         var product = productsRepo.GetByKey((System.Int32) id);
         productsRepo.Delete(product);
         uow.SaveChanges();
     }
     return RedirectToAction("Index");
 }