Beispiel #1
0
        public int Create(string Name)
        {
            VerifyToken();
            if (String.IsNullOrEmpty(Name))
            {
                throw new ArgumentNullException("name");
            }
            if (Name.Length > 50)
            {
                throw new ArgumentException("max size is 50", "Name");
            }
            Name = Name.ToLower();
            var Group = CdDb.Groups.SingleOrDefault(x => x.Name == Name);

            if (Group != null)
            {
                throw new ArgumentException("There is already a group with this name");
            }
            Group = new Groups()
            {
                Name      = Name,
                Active    = true,
                CreatedAt = DateTime.Now
            };
            CdDb.Groups.Add(Group);
            CdDb.SaveChanges();
            return(Group.Id);
        }
Beispiel #2
0
        public void DeleteTestFailWithUsers()
        {
            string Code = string.Empty;

            using (var TokenService = ServiceFinder.GetTokenService())
            {
                Code = TokenService.CreateToken(TokenType.WebAuth, 1);
            }

            var GroupService = ServiceFinder.GetGroupService(Code, TokenType.WebAuth);

            var CreatedId = GroupService.Create("DeleteTestGroup");

            using (var CdDb = new CDSEntities())
            {
                var User = CdDb.Users.SingleOrDefault(x => x.Id == 1);
                User.IdGroup = CreatedId;
                CdDb.SaveChanges();

                try
                {
                    GroupService.Delete(CreatedId);
                }
                catch (Exception)
                {
                    User.IdGroup = null;
                    CdDb.SaveChanges();
                    CdDb.Groups.Remove(CdDb.Groups.SingleOrDefault(x => x.Id == CreatedId));
                    CdDb.SaveChanges();
                    throw;
                }
            }
        }
Beispiel #3
0
        public void UpdateTest()
        {
            int LastContentId  = 0;
            var ContentService = GetAdminService();

            using (CDSEntities CdDb = new CDSEntities())
            {
                if (CdDb.Contents.Any())
                {
                    LastContentId = CdDb.Contents.Max(x => x.Id);
                }
                FileName = FileName + LastContentId;
                var CreatedId = ContentService.CreateContent(GroupIds, IdsGenre, IdType, FileName, Description, UploadedFiles, BeginDate, EndDate, false);

                ContentService.UpdateContent(CreatedId, GroupIds, IdsGenre, FileName + "D", Description + "D", UploadedFiles, DateTime.Today, DateTime.Today.AddDays(1), true);

                var DbContent = CdDb.Contents.SingleOrDefault(x => x.Id == CreatedId);

                Assert.IsTrue(DbContent.Name == FileName + "D");
                Assert.IsTrue(DbContent.Description == Description + "D");
                Assert.IsTrue(DbContent.BeginDeliveryDate == DateTime.Today);
                Assert.IsTrue(DbContent.EndDeliveryDate == DateTime.Today.AddDays(1));
                Assert.IsTrue(DbContent.IsBroadcast == true);


                CdDb.GroupContents.RemoveRange(CdDb.GroupContents.Where(x => x.IdContent == CreatedId));
                CdDb.SaveChanges();
                DbContent.Genres.Clear();
                CdDb.Contents.Remove(CdDb.Contents.SingleOrDefault(x => x.Id == CreatedId));
                CdDb.SaveChanges();
            }
        }
Beispiel #4
0
        public void Update(Users User)
        {
            VerifyToken();
            var DbUser = CdDb.Users.SingleOrDefault(x => x.Id == User.Id);
            var Group  = CdDb.Groups.SingleOrDefault(x => x.Id == User.IdGroup);

            if (DbUser == null)
            {
                throw new ArgumentException("Can't find specified user");
            }
            if (Group == null)
            {
                throw new ArgumentException("Invalid Id group");
            }
            if (!Group.Active)
            {
                throw new ArgumentException("Id must be of a active group");
            }


            //if (!Validate(User))
            //    throw new ArgumentException("Invalid User");
            DbUser.Name      = User.Name;
            DbUser.Adress    = User.Adress;
            DbUser.BirthDate = User.BirthDate;
            DbUser.Phone     = User.Phone;
            DbUser.State     = User.State;
            DbUser.CEP       = User.CEP;
            DbUser.Cellphone = User.Cellphone;
            DbUser.Gender    = User.Gender;
            DbUser.IdGroup   = User.IdGroup;

            CdDb.SaveChanges();
        }
Beispiel #5
0
        public void createTest()
        {
            var id = genreService.Create(testName);

            var dbEntity = cdDb.Genres.SingleOrDefault(x => x.Id == id);

            Assert.IsNotNull(dbEntity);

            cdDb.Genres.Remove(dbEntity);
            cdDb.SaveChanges();
        }
Beispiel #6
0
        public string CreateToken(TokenType Type, int IdUser, int?IdContent = null)
        {
            DeleteExpiredTokens();
            int IdTokenType = GetTokenTypeId(Type);
            var Token       = CdDb.Tokens.FirstOrDefault(x => x.IdType == IdTokenType && x.IdUser == IdUser && x.IdContent == IdContent);

            if (Token == null)
            {
                Token = GenerateNewToken(Type, IdUser, IdContent);
                CdDb.Tokens.Add(Token);
            }
            Token.ExpireDate = GetExpireDate(Type);
            CdDb.SaveChanges();

            return(Token.Code);
        }
Beispiel #7
0
        public void UpdateTest()
        {
            var UserService = GetService();
            int CreatedId   = UserService.Create(MockAddUser, "testcom01", "");

            MockUpdateUser.Id = CreatedId;
            UserService.Update(MockUpdateUser);

            using (var CdDb = new CDSEntities())
            {
                var DbUser = CdDb.Users.SingleOrDefault(x => x.Id == CreatedId);
                Assert.IsNotNull(DbUser);

                Assert.AreEqual(DbUser.Adress, MockUpdateUser.Adress);
                Assert.AreEqual(DbUser.BirthDate, MockUpdateUser.BirthDate);
                Assert.AreEqual(DbUser.Cellphone, MockUpdateUser.Cellphone);
                Assert.AreEqual(DbUser.CEP, MockUpdateUser.CEP);
                Assert.AreEqual(DbUser.Gender, MockUpdateUser.Gender);
                Assert.AreEqual(DbUser.IdGroup, MockUpdateUser.IdGroup);
                Assert.AreEqual(DbUser.Name, MockUpdateUser.Name);
                Assert.AreEqual(DbUser.Phone, MockUpdateUser.Phone);
                Assert.AreEqual(DbUser.State, MockUpdateUser.State);

                CdDb.Users.Remove(DbUser);
                CdDb.SaveChanges();
            }
        }
Beispiel #8
0
        public void CreateTest()
        {
            var UserService = GetService();
            int CreatedId   = UserService.Create(MockAddUser, mockPwd, "");

            using (CDSEntities CdDb = new CDSEntities())
            {
                var DbUser = CdDb.Users.SingleOrDefault(x => x.Id == CreatedId);
                Assert.IsNotNull(DbUser);
                Assert.IsTrue(DbUser.IdType != 1);
                CdDb.Users.Remove(DbUser);
                CdDb.SaveChanges();
            }
        }
Beispiel #9
0
        public void DeleteTestFailWithContents()
        {
            string Code = string.Empty;

            using (var TokenService = ServiceFinder.GetTokenService())
            {
                Code = TokenService.CreateToken(TokenType.WebAuth, 1);
            }

            var GroupService = ServiceFinder.GetGroupService(Code, TokenType.WebAuth);

            var CreatedId = GroupService.Create("DeleteTestGroup");

            using (var CdDb = new CDSEntities())
            {
                CdDb.GroupContents.Add(new GroupContents()
                {
                    IdContent = 24,
                    IdGroup   = CreatedId,
                    CreatedAt = DateTime.Now
                });
                CdDb.SaveChanges();
                try
                {
                    GroupService.Delete(CreatedId);
                }
                catch (Exception)
                {
                    CdDb.GroupContents.RemoveRange(CdDb.GroupContents.Where(x => x.IdGroup == CreatedId));
                    CdDb.SaveChanges();
                    CdDb.Groups.Remove(CdDb.Groups.SingleOrDefault(x => x.Id == CreatedId));
                    CdDb.SaveChanges();
                    throw;
                }
            }
        }
Beispiel #10
0
        public int Create(Users User, string Password, string ActivateUrl)
        {
            //VerifyToken();

            if (!Validate(User))
            {
                return(0);
            }
            User.IdType = 2;
            using (var CdDb = new CDSEntities())
            {
                var Group = CdDb.Groups.SingleOrDefault(x => x.Id == User.IdGroup);

                if (Group == null)
                {
                    throw new ArgumentException("Invalid Id group");
                }
                if (!Group.Active)
                {
                    throw new ArgumentException("Id must be of a active group");
                }

                User.Password  = AuthService.CreateEncryptedPassword(Password);
                User.Active    = true;
                User.CreatedAt = DateTime.Now;
                CdDb.Users.Add(User);
                CdDb.SaveChanges();

                try
                {
                    SendActiveAccountEmail(User.Name, User.Email, User.Id, ActivateUrl);
                }
                catch { }

                return(User.Id);
            }
        }
Beispiel #11
0
 private void Save()
 {
     cdDb.SaveChanges();
 }