示例#1
0
        public JsonResult Create(Venue Venue)
        {
            String Error = "";

            try
            {
                Venue.Status = (int)Statuses.Venue.Approve;

                if (!ModelState.IsValid)
                {
                    TempData["Error"] = "Dữ liệu không hợp lệ";
                }

                var addedRecord = Repository.AddOrUpdate(Venue);
                unitOfWork.Save();

                TempData["Message"] = "Đã tạo mới thành công địa điểm " + Venue.VenueName;
                return(Json(new
                {
                    Result = "OK"
                }));
            }
            catch (Exception e)
            {
                Error = "Có lỗi xảy ra";
            }

            return(Json(new
            {
                Result = "ERROR",
                Message = Error
            }));
        }
        public JsonResult Create(Category Category)
        {
            String Error = "";

            try
            {
                Category.Status = (int)Statuses.Category.Active;

                if (!ModelState.IsValid)
                {
                    TempData["Error"] = "Dữ liệu không hợp lệ";
                }

                var addedRecord = Repository.AddOrUpdate(Category);
                unitOfWork.Save();

                TempData["Message"] = "Đã tạo thành công danh mục mới! " + Category.CategoryName;
                return(Json(new
                {
                    Result = "OK"
                }));
            }
            catch (Exception e)
            {
                Error = "Có lỗi xảy ra";
            }

            return(Json(new
            {
                Result = "ERROR",
                Message = Error
            }));
        }
        public void ShouldAddOrUpdateExistingEmployee_AddIfDoesNotExist()
        {
            // Arrange
            var employee1Update = CreateEmployee1();

            employee1Update.FirstName = "Added " + employee1Update.FirstName;
            employee1Update.Country   = Testdata.Countries.CreateCountrySwitzerland();

            // Act
            ChangeSet committedChangeSet;

            using (IGenericRepository <Employee> employeeRepository = new GenericRepository <Employee>(this.CreateContext()))
            {
                employee1Update    = employeeRepository.AddOrUpdate(employee1Update);
                committedChangeSet = employeeRepository.Save();
            }

            // Assert
            committedChangeSet.Assert(expectedNumberOfAdded: 2, expectedNumberOfModified: 0, expectedNumberOfDeleted: 0);

            using (IGenericRepository <Employee> employeeRepository = new GenericRepository <Employee>(this.CreateContext()))
            {
                var allEmployees = employeeRepository.GetAll().ToList();
                allEmployees.Should().HaveCount(1);
                allEmployees.ElementAt(0).Id.Should().Be(employee1Update.Id);
                allEmployees.ElementAt(0).FirstName.Should().Contain("Added");
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            var loadFile = File.ReadAllLines(@"c:\users\luiz.araujo\documents\visual studio 2015\Projects\FinancialDic\FinancialDic.Load\load.csv");

            _repository = new GenericRepository<Word>();

            var count = 0;

            foreach (var line in loadFile)
            {
                var words = line.Split(';');

                count ++;

                var word = new Word()
                {
                    Id = count,
                    Portuguese = words[0],
                    English = words[1]
                };

                _repository.AddOrUpdate(word);
            }

            Console.WriteLine("Fim");
        }
示例#5
0
        public async Task CanLoginIfDataIsCorrect()
        {
            var options           = new DbContextOptionsBuilder <SPDbContext>().UseInMemoryDatabase("inMemoryDb.db").Options;
            var ctx               = new SPDbContext(options);
            var repo              = new GenericRepository <Person>(ctx);
            var encryptedPassword = Helper.PasswordHelper.GetHash("password1");

            repo.AddOrUpdate(new Model.Person {
                FirstName = "Test", Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });
            repo.AddOrUpdate(new Model.Person {
                FirstName = "Test", Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });
            repo.AddOrUpdate(new Model.Person {
                FirstName = "Test", Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });


            LoginViewModel sut = new LoginViewModel("unitTest", new PeopleLogic(repo));


            //Assert.IsFalse(sut.CanLogin());
            sut.UserName = "******";
            sut.Password = "******";
            Assert.IsFalse(await sut.CanLogin());

            sut.UserName = "******";
            sut.Password = "******";
            Assert.IsTrue(await sut.CanLogin());

            IWindowService _fakeWin = ServiceContainer.GetService <IWindowService>();

            Assert.IsTrue(sut.LogInCommand.CanExecute(null));
            //sut.LogInCommand.Execute(null);
        }
        public void ThrowArgumentNullException_When_InvokedWithNullValue()
        {
            var contextMock = new Mock <IBookstoreContext>();

            var bookRepository = new GenericRepository <Book>(contextMock.Object);

            Book nullBook = null;

            Assert.ThrowsException <ArgumentNullException>(() => bookRepository.AddOrUpdate(It.IsAny <Expression <Func <Book, object> > >(), nullBook));
        }
示例#7
0
        public void CheckWrongUserDataMustGenerateValidationErrors()
        {
            var options           = new DbContextOptionsBuilder <SPDbContext>().UseInMemoryDatabase("inMemoryDb.db").Options;
            var ctx               = new SPDbContext(options);
            var repo              = new GenericRepository <Person>(ctx);
            var encryptedPassword = Helper.PasswordHelper.GetHash("password1");

            repo.AddOrUpdate(new Model.Person {
                Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });
            repo.AddOrUpdate(new Model.Person {
                Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });
            repo.AddOrUpdate(new Model.Person {
                Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });


            LoginViewModel sut = new LoginViewModel("unitTest", new PeopleLogic(repo));


            //Ohne Daten gibt Error
            sut.UserName = "";
            sut.Password = "";
            Assert.IsTrue(sut.IsValid);

            //Usernamen mit weniger als drei zeichen gibt es sowieso nicht also ist es auch nicht valid
            sut.UserName = "******";
            sut.Password = "******";
            Assert.IsTrue(sut.IsValid);

            Assert.AreEqual("Username ist zu kurz", sut.ValidationErrors().First().ErrorMessage);
            Assert.AreEqual(nameof(sut.UserName), sut.ValidationErrors().First().MemberNames.First());
        }
        public JsonResult Create(Province province)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new JSONResult("Form is not valid")));
                }

                var addedRecord = Repository.AddOrUpdate(province);
                unitOfWork.Save();
                return(Json(new JSONResult(addedRecord, "Record")));
            }
            catch (Exception e)
            {
                return(Json(new JSONResult(e)));

                throw;
            }
        }
示例#9
0
        public void CheckIfCanLoginFalseIfMissingData()
        {
            var options           = new DbContextOptionsBuilder <SPDbContext>().UseInMemoryDatabase("inMemoryDb.db").Options;
            var ctx               = new SPDbContext(options);
            var repo              = new GenericRepository <Person>(ctx);
            var encryptedPassword = Helper.PasswordHelper.GetHash("password1");

            repo.AddOrUpdate(new Model.Person {
                Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });
            repo.AddOrUpdate(new Model.Person {
                Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });
            repo.AddOrUpdate(new Model.Person {
                Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });


            LoginViewModel sut = new LoginViewModel("unitTest", new PeopleLogic(repo));


            //Assert.IsFalse(sut.CanLogin());
            sut.UserName = "";
            sut.Password = "";
            Assert.IsFalse(sut.LogInCommand.CanExecute(null));

            sut.UserName = "******";
            sut.Password = "******";
            Assert.IsTrue(sut.LogInCommand.CanExecute(null));
        }
示例#10
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            using (UnitOfWork uof = new UnitOfWork(new NorthwindEntities()))
            {
                GenericRepository <Orders> repo = uof.Repository <Orders>();
                Orders order = new Orders();
                order.CustomerID = "VINET";

                repo.AddOrUpdate(order);

                uof.SaveChanges();

                //取得新的自動編號
                logger.DebugFormat("new Id: {0}", order.OrderID);
            }
        }
示例#11
0
 public virtual HttpResponseMessage AddOrUpdate(List <T> entities)
 {
     try
     {
         foreach (var entity in entities)
         {
             AddStandardValues(entity);
         }
         return(Request.CreateResponse(HttpStatusCode.OK, _repository.AddOrUpdate(entities)));
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "Could not Delete entity for type: " + typeof(T).GetType());
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
示例#12
0
        public void PasswordValidationTest()
        {
            var options           = new DbContextOptionsBuilder <SPDbContext>().UseInMemoryDatabase("inMemoryDb.db").Options;
            var ctx               = new SPDbContext(options);
            var repo              = new GenericRepository <Person>(ctx);
            var encryptedPassword = Helper.PasswordHelper.GetHash("password1");

            repo.AddOrUpdate(new Model.Person {
                Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });
            LoginViewModel sut = new LoginViewModel("unitTest", new PeopleLogic(repo));

            Assert.AreEqual(3, sut.ValidationErrors().Count);
            sut.Password = "******";
            Assert.AreEqual(2, sut.ValidationErrors().Count);
            Assert.IsTrue(sut.ValidationErrors().First().MemberNames.First() == nameof(sut.UserName));
        }
示例#13
0
        public void InitVmMustSetDisplayText()
        {
            var options           = new DbContextOptionsBuilder <SPDbContext>().UseInMemoryDatabase("inMemoryDb.db").Options;
            var ctx               = new SPDbContext(options);
            var repo              = new GenericRepository <Person>(ctx);
            var encryptedPassword = Helper.PasswordHelper.GetHash("password1");

            repo.AddOrUpdate(new Model.Person {
                Credentials = new Model.AccessData()
                {
                    UserName = "******", EncryptedPassword = encryptedPassword
                }
            });
            LoginViewModel sut = new LoginViewModel("TestText", new PeopleLogic(repo));

            Assert.IsNotNull(sut.DisplayText);


            Assert.IsNotNull(sut.DisplayText);
            Assert.AreEqual("TestText", sut.DisplayText);
        }
示例#14
0
        public void UserShouldBeCorrectAddedToStorageWhenThereIsNoSuchUsers()
        {
            //arrange
            var user = new User
            {
                Id       = Guid.NewGuid(),
                Name     = "Fake User",
                Login    = "******",
                Password = "******"
            };

            //act
            _usersRepositoryUnderTest.AddOrUpdate(user);
            //assert
            _stubStorage
            .Should()
            .Contain(x => x.Id == user.Id &&
                     x.Name == user.Name &&
                     x.Login == user.Login &&
                     x.Password == user.Password);
        }
        public void ShouldAddOrUpdateExistingEmployee_UpdateIfExists()
        {
            // Arrange
            var originalEmployee = CreateEmployee1();

            using (IGenericRepository <Employee> employeeRepository = new GenericRepository <Employee>(this.CreateContext()))
            {
                employeeRepository.Add(originalEmployee);
                employeeRepository.Save();
            }

            var updateEmployee = CreateEmployee1();

            updateEmployee.Id         = originalEmployee.Id;
            updateEmployee.RowVersion = originalEmployee.RowVersion;
            updateEmployee.FirstName  = "Updated " + updateEmployee.FirstName;

            // Act
            ChangeSet committedChangeSet;

            using (IGenericRepository <Employee> employeeRepository = new GenericRepository <Employee>(this.CreateContext()))
            {
                updateEmployee     = employeeRepository.AddOrUpdate(updateEmployee);
                committedChangeSet = employeeRepository.Save();
            }

            // Assert
            committedChangeSet.Assert(expectedNumberOfAdded: 0, expectedNumberOfModified: 1, expectedNumberOfDeleted: 0);

            using (IGenericRepository <Employee> employeeRepository = new GenericRepository <Employee>(this.CreateContext()))
            {
                var allEmployees = employeeRepository.GetAll().ToList();
                allEmployees.Should().HaveCount(1);
                allEmployees.ElementAt(0).FirstName.Should().Contain("Updated");
            }
        }
示例#16
0
        public JsonResult Event(int Id, int FollowType)
        {
            //try
            //{
            int UserId = WebSecurity.GetUserId(User.Identity.Name);
            GenericRepository <UserFollowEvent> Repository = uow.FollowEventRepository;
            UserFollowEvent Follow = Repository.Get(f => f.UserId == UserId && f.EventId == Id).FirstOrDefault();

            if (FollowType == -1)
            {
                if (Follow == null)
                {
                    //return Json(new
                    //{
                    //    Result = "ERROR",
                    //    Message = "UserDoesNotFollow",
                    //    FollowType = -1
                    //});
                }
                else
                {
                    Repository.Delete(Follow);
                    Repository.Save();
                }
                return(Json(new
                {
                    Result = "OK",
                    FollowType = -1
                }));
            }
            else
            {
                if (Follow == null)
                {
                    Follow = new UserFollowEvent
                    {
                        UserId  = UserId,
                        EventId = Id
                    };
                }
                Follow.FollowType = FollowType;
                Repository.AddOrUpdate(Follow);
                Repository.Save();

                return(Json(new
                {
                    Result = "OK",
                    FollowType = FollowType
                }));
            }



            //}
            //catch (Exception e)
            //{
            //    return Json(new
            //    {
            //        Result = "ERROR",
            //        Message = e.Message
            //    });
            //}
        }