Esempio n. 1
0
        private void CreateSlug(Topic topic)
        {
            var slug = ServiceHelpers.CreateUrl(topic.Name);

            if (!TestSlug(topic.Slug, slug))
            {
                var tmpSlug = slug;

                var Cmd = _context.CreateCommand();
                Cmd.CommandText = "SELECT Slug FROM [Topic] WHERE [Slug] LIKE @Slug AND [Id] != @Id ";

                Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = topic.Id;
                Cmd.Parameters.Add("Slug", SqlDbType.NVarChar).Value       = string.Concat(slug, "%");

                DataTable data = Cmd.findAll();
                Cmd.Close();

                int i = 0;
                while (!CheckSlug(tmpSlug, data))
                {
                    i++;
                    tmpSlug = string.Concat(slug, "-", i);
                }

                topic.Slug = tmpSlug;
            }
        }
Esempio n. 2
0
        public void Add(Booking booking)
        {
            //string cachekey = string.Concat(CacheKeys.Category.StartsWith, "getSetting-", key);

            var Cmd = _context.CreateCommand();

            booking.CreateDate = DateTime.UtcNow;

            Cmd.CommandText = "INSERT INTO [Booking]([Id],[NamePartner],[CheckIn],[CheckOut],[Adukts],[Adolescent],[Children],[TypeRoom_Id],[Phone],[Email],[IsCheck],[Note],[CreateDate])"
                              + " VALUES(@Id,@NamePartner,@CheckIn,@CheckOut,@Adukts,@Adolescent,@Children,@TypeRoom_Id,@Phone,@Email,@IsCheck,@Note,@CreateDate)";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = booking.Id;
            Cmd.AddParameters("NamePartner", booking.NamePartner);
            Cmd.AddParameters("CheckIn", booking.CheckIn);
            Cmd.AddParameters("CheckOut", booking.CheckOut);
            Cmd.AddParameters("Adukts", booking.Adukts);
            Cmd.AddParameters("Adolescent", booking.Adolescent);
            Cmd.AddParameters("Children", booking.Children);
            Cmd.AddParameters("TypeRoom_Id", booking.TypeRoom_Id);
            Cmd.AddParameters("IsCheck", booking.IsCheck);
            Cmd.AddParameters("Phone", booking.Phone);
            Cmd.AddParameters("Note", booking.Note);
            Cmd.AddParameters("Email", booking.Email);
            Cmd.AddParameters("CreateDate", booking.CreateDate);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.Booking.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add Booking false");
            }
        }
Esempio n. 3
0
        public void Add(TypeRoom typeRoom)
        {
            var Cmd = _context.CreateCommand();

            typeRoom.CreateDate = DateTime.UtcNow;

            Cmd.CommandText = "INSERT INTO [TypeRoom]([Id],[Name],[IsShow],[Note],[CreateDate])"
                              + " VALUES(@Id,@Name,@IsShow,@Note,@CreateDate)";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = typeRoom.Id;
            Cmd.AddParameters("Name", typeRoom.Name);
            Cmd.AddParameters("IsShow", typeRoom.IsShow);
            Cmd.AddParameters("Note", typeRoom.Note);
            Cmd.AddParameters("CreateDate", typeRoom.CreateDate);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.TypeRoom.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add TypeRoom false");
            }
        }
Esempio n. 4
0
        public void Add(Carousel menu)
        {
            using (var Cmd = _context.CreateCommand())
            {
                bool rt = Cmd.Add <Carousel>(menu) > 0;

                Cmd.cacheStartsWithToClear(CacheKeys.Carousel.StartsWith);
                if (!rt)
                {
                    throw new Exception("Add Carousel false");
                }
            }

            //    var Cmd = _context.CreateCommand();

            //Cmd.CommandText = "INSERT INTO [dbo].[Carousel]([Id],[Carousel_Id],[Name],[Description],[Link],[Image],[SortOrder])"
            //    + " VALUES(@Id,@Carousel_Id,@Name,@Description,@Link,@Image,@SortOrder)";

            //Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = menu.Id;
            //Cmd.AddParameters("Name", menu.Name);
            //Cmd.AddParameters("Description", menu.Description);
            //Cmd.AddParameters("Link", menu.Link);
            //Cmd.AddParameters("Image", menu.Image);
            //Cmd.AddParameters("SortOrder", menu.SortOrder);
            //Cmd.AddParameters("Carousel_Id", menu.Carousel_Id);

            //bool rt = Cmd.command.ExecuteNonQuery() > 0;
            //Cmd.cacheStartsWithToClear(CacheKeys.Carousel.StartsWith);
            //Cmd.Close();

            //if (!rt) throw new Exception("Add Carousel false");
        }
Esempio n. 5
0
        public void Add(ShoppingCart cat)
        {
            var Cmd = _context.CreateCommand();

            cat.CreateDate = DateTime.UtcNow;

            Cmd.CommandText = "INSERT INTO [dbo].[ShoppingCart]([Id],[Name],[Email] ,[Phone],[Addren],[ShipName],[ShipPhone] ,[ShipAddren] ,[ShipNote],[TotalMoney],[Note],[Status],[CreateDate])"
                              + " VALUES(@Id,@Name,@Email,@Phone,@Addren,@ShipName,@ShipPhone,@ShipAddren,@ShipNote,@TotalMoney,@Note,@Status,@CreateDate)";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = cat.Id;
            Cmd.AddParameters("Name", cat.Name);
            Cmd.AddParameters("Email", cat.Email);
            Cmd.AddParameters("Phone", cat.Phone);
            Cmd.AddParameters("Addren", cat.Addren);
            Cmd.AddParameters("ShipName", cat.ShipName);
            Cmd.AddParameters("ShipPhone", cat.ShipPhone);
            Cmd.AddParameters("ShipAddren", cat.ShipAddren);
            Cmd.AddParameters("ShipNote", cat.ShipNote);
            Cmd.AddParameters("TotalMoney", cat.TotalMoney);
            Cmd.AddParameters("Note", cat.Note);
            Cmd.AddParameters("Status", cat.Status);
            Cmd.AddParameters("CreateDate", cat.CreateDate);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.ShoppingCart.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add ShoppingCart false");
            }
        }
Esempio n. 6
0
        public void Add(Menu menu)
        {
            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "INSERT INTO [dbo].[Menu]([Id],[Menu_Id],[Name],[Description],[iType],[Link],[Image],[Colour],[SortOrder])"
                              + " VALUES(@Id,@Menu_Id,@Name,@Description,@iType,@Link,@Image,@Colour,@SortOrder)";

            Cmd.AddParameters("Id", menu.Id);
            Cmd.AddParameters("Name", menu.Name);
            Cmd.AddParameters("Description", menu.Description);
            Cmd.AddParameters("Colour", menu.Colour);
            Cmd.AddParameters("iType", menu.iType);
            Cmd.AddParameters("Link", menu.Link);
            Cmd.AddParameters("Image", menu.Image);
            Cmd.AddParameters("SortOrder", menu.SortOrder);
            Cmd.AddParameters("Menu_Id", menu.Menu_Id);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.Menu.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add Menu false");
            }
        }
        public MembershipLogin Get(Guid Id)
        {
            using (var Cmd = _context.CreateCommand())
            {
                Cmd.CommandText = "SELECT * FROM [dbo].[MembershipLogin] WHERE [Id] = @Id";
                Cmd.AddParameters("Id", Id);

                return(Cmd.FindFirst <MembershipLogin>());
            }
        }
Esempio n. 8
0
        public void Add(Category cat)
        {
            //string cachekey = string.Concat(CacheKeys.Category.StartsWith, "getSetting-", key);

            var Cmd = _context.CreateCommand();

            cat.DateCreated = DateTime.UtcNow;
            CreateSlug(cat);


            Cmd.CommandText = "INSERT INTO [Category]([Id],[Name],[Description],[IsLocked],[ModerateTopics],[ModeratePosts],[SortOrder]"
                              + ",[DateCreated],[Slug],[PageTitle],[Path],[MetaDescription],[Colour],[Image],[Category_Id],[IsProduct])"
                              + " VALUES(@Id,@Name,@Description,@IsLocked,@ModerateTopics,@ModeratePosts,@SortOrder"
                              + ",@DateCreated,@Slug,@PageTitle,@Path,@MetaDescription,@Colour,@Image,@Category_Id,@IsProduct)";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = cat.Id;
            Cmd.AddParameters("Name", cat.Name);
            Cmd.AddParameters("Description", cat.Description);
            Cmd.AddParameters("IsLocked", cat.IsLocked);
            Cmd.AddParameters("ModerateTopics", cat.ModerateTopics);
            Cmd.AddParameters("ModeratePosts", cat.ModeratePosts);
            Cmd.AddParameters("SortOrder", cat.SortOrder);
            Cmd.AddParameters("DateCreated", cat.DateCreated);
            Cmd.AddParameters("Slug", cat.Slug);
            Cmd.AddParameters("PageTitle", cat.PageTitle);
            Cmd.AddParameters("Path", cat.Path);
            Cmd.AddParameters("MetaDescription", cat.MetaDescription);
            Cmd.AddParameters("Colour", cat.Colour);
            Cmd.AddParameters("Image", cat.Image);
            Cmd.AddParameters("Category_Id", cat.Category_Id);
            Cmd.AddParameters("IsProduct", cat.IsProduct);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.Category.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add Category false");
            }
        }
Esempio n. 9
0
        public string GetSettingNoCache(string key)
        {
            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "SELECT [VALUE] FROM tblSetting WHERE STKEY = @STKEY";
            Cmd.AddParameters("STKEY", key);

            var rt = Cmd.command.ExecuteScalar();

            string cachedSettings = null;

            if (rt != null)
            {
                cachedSettings = Cmd.command.ExecuteScalar().ToString();
            }

            Cmd.Close();

            return(cachedSettings);
        }
Esempio n. 10
0
        public void Add(EmployeesRole role)
        {
            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "INSERT INTO [EmployeesRole]([Id],[Name],[Description])"
                              + " VALUES(@Id,@Name,@Description)";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = role.Id;
            Cmd.AddParameters("Name", role.Name);
            Cmd.AddParameters("Description", role.Description);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.EmployeesRole.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add EmployeesRole false");
            }
        }
Esempio n. 11
0
        public void Add(Contact contact)
        {
            //string cachekey = string.Concat(CacheKeys.Category.StartsWith, "getSetting-", key);

            var Cmd = _context.CreateCommand();

            contact.CreateDate = DateTime.UtcNow;

            Cmd.CommandText = "INSERT INTO [Contact]([Id],[Name],[Email],[Content],[IsCheck],[Note],[CreateDate])"
                              + " VALUES(@Id,@Name,@Email,@Content,@IsCheck,@Note,@CreateDate)";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = contact.Id;
            Cmd.AddParameters("Name", contact.Name);
            Cmd.AddParameters("Email", contact.Email);
            Cmd.AddParameters("Content", contact.Content);
            Cmd.AddParameters("IsCheck", contact.IsCheck);
            Cmd.AddParameters("Note", contact.Note);
            Cmd.AddParameters("CreateDate", contact.CreateDate);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.Contact.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add Contact false");
            }
        }
Esempio n. 12
0
        public List <Permission> GetPermissions(List <MembershipRole> roles)
        {
            if (roles == null || roles.Count == 0)
            {
                return(new List <Permission>());
            }
            roles.Sort();
            string InRoles = "(";

            for (int i = 0; i < roles.Count; i++)
            {
                if (i == 0)
                {
                    InRoles += roles[i].Id.ToString();
                }
                else
                {
                    InRoles += "," + roles[i].Id.ToString();
                }
            }
            InRoles += ")";

            string cachekey       = string.Concat(CacheKeys.Permission.StartsWith, "GetPermissions-", InRoles);
            var    cachedSettings = _cacheService.Get <List <Permission> >(cachekey);

            if (cachedSettings == null)
            {
                using (var Cmd = _context.CreateCommand())
                {
                    Cmd.CommandText = "SELECT P.* FROM [dbo].[Permission] AS P INNER JOIN [dbo].[PermissionsInRoles] AS K ON P.[Id] = K.[PermissionId]  WHERE K.[RoleId] IN " + InRoles;

                    cachedSettings = Cmd.FindAll <Permission>();
                }

                _cacheService.Set(cachekey, cachedSettings, CacheTimes.OneDay);
            }

            return(cachedSettings);
        }
Esempio n. 13
0
        public void AddMembershipRole(MembershipRole role)
        {
            var Cmd = _context.CreateCommand();

            Cmd.cacheStartsWithToClear(CacheKeys.Role.StartsWith);

            Cmd.CommandText  = "IF NOT EXISTS (SELECT * FROM [MembershipRole] WHERE [Id] = @Id OR [RoleName] = @RoleName)";
            Cmd.CommandText += " BEGIN INSERT INTO [MembershipRole]([Id],[RoleName])";
            Cmd.CommandText += " VALUES(@Id,@RoleName) END ";

            Cmd.AddParameters("Id", role.Id);
            Cmd.AddParameters("RoleName", role.RoleName);

            bool ret = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.Close();

            if (!ret)
            {
                throw new Exception("Add MembershipRole false");
            }
        }
Esempio n. 14
0
        public void Add(Post post)
        {
            post.DateCreated = DateTime.UtcNow;
            post.DateEdited  = post.DateCreated;

            var Cmd = _context.CreateCommand();

            Cmd.cacheStartsWithToClear(CacheKeys.Permission.StartsWith);

            Cmd.CommandText  = "IF NOT EXISTS (SELECT * FROM [Post] WHERE [Id] = @Id)";
            Cmd.CommandText += " BEGIN INSERT INTO [Post]([Id],[PostContent],[DateCreated],[VoteCount],[DateEdited],[IsSolution],[IsTopicStarter],[FlaggedAsSpam],[IpAddress],[Pending],[SearchField],[InReplyTo],[Topic_Id],[MembershipUser_Id])";
            Cmd.CommandText += " VALUES(@Id,@PostContent,@DateCreated,@VoteCount,@DateEdited,@IsSolution,@IsTopicStarter,@FlaggedAsSpam,@IpAddress,@Pending,@SearchField,@InReplyTo,@Topic_Id,@MembershipUser_Id) END ";

            Cmd.AddParameters("Id", post.Id);
            Cmd.AddParameters("PostContent", post.PostContent);
            Cmd.AddParameters("DateCreated", post.DateCreated);
            Cmd.AddParameters("VoteCount", post.VoteCount);
            Cmd.AddParameters("DateEdited", post.DateEdited);
            Cmd.AddParameters("IsSolution", post.IsSolution);
            Cmd.AddParameters("IsTopicStarter", post.IsTopicStarter);
            Cmd.AddParameters("FlaggedAsSpam", post.FlaggedAsSpam);
            Cmd.AddParameters("IpAddress", post.IpAddress);
            Cmd.AddParameters("Pending", post.Pending);
            Cmd.AddParameters("SearchField", post.SearchField);
            Cmd.AddParameters("InReplyTo", post.InReplyTo);
            Cmd.AddParameters("Topic_Id", post.Topic_Id);
            Cmd.AddParameters("MembershipUser_Id", post.MembershipUser_Id);

            bool ret = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.Post.StartsWith);
            Cmd.Close();

            if (!ret)
            {
                throw new Exception("Add Post false");
            }
        }
Esempio n. 15
0
        public void Add(ShoppingCartProduct cat)
        {
            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "INSERT INTO [dbo].[ShoppingCartProduct]([Id],[CountProduct],[Price] ,[ProductId],[ShoppingCartId])"
                              + " VALUES(@Id,@CountProduct,@Price,@ProductId,@ShoppingCartId)";

            Cmd.AddParameters("Id", cat.Id);
            Cmd.AddParameters("CountProduct", cat.CountProduct);
            Cmd.AddParameters("Price", cat.Price);
            Cmd.AddParameters("ProductId", cat.ProductId);
            Cmd.AddParameters("ShoppingCartId", cat.ShoppingCartId);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.ShoppingCartProduct.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add ShoppingCartProduct false");
            }
        }
Esempio n. 16
0
        public void Add(Permission role)
        {
            var Cmd = _context.CreateCommand();

            Cmd.cacheStartsWithToClear(CacheKeys.Permission.StartsWith);

            Cmd.CommandText  = "IF NOT EXISTS (SELECT * FROM [Permission] WHERE [Id] = @Id OR [Name] = @Name)";
            Cmd.CommandText += " BEGIN INSERT INTO [Permission]([Id],[Name],[IsGlobal])";
            Cmd.CommandText += " VALUES(@Id,@Name,@IsGlobal) END ";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = role.Id;
            Cmd.Parameters.Add("Name", SqlDbType.NVarChar).Value       = role.Name;
            Cmd.Parameters.Add("IsGlobal", SqlDbType.NVarChar).Value   = role.IsGlobal;

            bool ret = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.Close();

            if (!ret)
            {
                throw new Exception("Add Permission false");
            }
        }
Esempio n. 17
0
        public void Add(Employees emp)
        {
            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "INSERT INTO [Employees]([Id],[RoleId],[Name],[Phone],[Email],[Skype])"
                              + " VALUES(@Id,@RoleId,@Name,@Phone,@Email,@Skype)";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value     = emp.Id;
            Cmd.Parameters.Add("RoleId", SqlDbType.UniqueIdentifier).Value = emp.RoleId;
            Cmd.AddParameters("Name", emp.Name);
            Cmd.AddParameters("Phone", emp.Phone);
            Cmd.AddParameters("Email", emp.Email);
            Cmd.AddParameters("Skype", emp.Skype);

            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.Employees.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add Employees false");
            }
        }
Esempio n. 18
0
        public void Add(MembershipUser User)
        {
            //string cachekey = string.Concat(CacheKeys.Member.StartsWith, "getSetting-", key);

            var Cmd = _context.CreateCommand();

            Cmd.CommandText  = "IF NOT EXISTS (SELECT * FROM MembershipUser WHERE Id = @Id OR UserName = @UserName OR Email = @Email)";
            Cmd.CommandText += " BEGIN INSERT INTO MembershipUser(Id,UserName,Password,PasswordSalt,Email,CreateDate,LastLockoutDate,LastPasswordChangedDate,LastLoginDate,IsLockedOut,IsApproved,IsBanned,FailedPasswordAttemptCount,FailedPasswordAnswerAttempt,Slug)";
            Cmd.CommandText += " VALUES(@Id,@UserName,@Password,@PasswordSalt,@Email,@CreateDate,@LastLockoutDate,@LastPasswordChangedDate,@LastLoginDate,@IsLockedOut,@IsApproved,@IsBanned,@FailedPasswordAttemptCount,@FailedPasswordAnswerAttempt,@Slug) END ";

            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value              = User.Id;
            Cmd.Parameters.Add("UserName", SqlDbType.NVarChar).Value                = User.UserName;
            Cmd.Parameters.Add("Password", SqlDbType.NVarChar).Value                = User.Password;
            Cmd.Parameters.Add("PasswordSalt", SqlDbType.NVarChar).Value            = User.PasswordSalt;
            Cmd.Parameters.Add("Email", SqlDbType.NVarChar).Value                   = User.Email;
            Cmd.Parameters.Add("CreateDate", SqlDbType.DateTime).Value              = User.CreateDate;
            Cmd.Parameters.Add("LastLockoutDate", SqlDbType.DateTime).Value         = User.LastLockoutDate;
            Cmd.Parameters.Add("LastPasswordChangedDate", SqlDbType.DateTime).Value = User.LastPasswordChangedDate;
            Cmd.Parameters.Add("LastLoginDate", SqlDbType.DateTime).Value           = User.LastLoginDate;
            Cmd.Parameters.Add("IsLockedOut", SqlDbType.Bit).Value                  = User.IsLockedOut;
            Cmd.Parameters.Add("IsApproved", SqlDbType.Bit).Value                   = User.IsApproved;
            Cmd.Parameters.Add("IsBanned", SqlDbType.Bit).Value = User.IsBanned;
            Cmd.Parameters.Add("FailedPasswordAttemptCount", SqlDbType.Int).Value  = User.FailedPasswordAttemptCount;
            Cmd.Parameters.Add("FailedPasswordAnswerAttempt", SqlDbType.Int).Value = User.FailedPasswordAnswerAttempt;
            Cmd.Parameters.Add("Slug", SqlDbType.NVarChar).Value = User.Slug;


            bool ret = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.Member.StartsWith);
            Cmd.Close();

            if (ret)
            {
                throw new Exception("Add MembershipUser false");
            }
        }
Esempio n. 19
0
        private Dictionary <string, string> GetAllLang(Guid id)
        {
            if (!Alllang.ContainsKey(id))
            {
                DataTable data;
                using (var Cmd = _context.CreateCommand())
                {
                    Cmd.CommandText = "SELECT KY.[Name],ST.[ResourceValue] FROM [LocaleStringResource] AS ST"
                                      + " INNER JOIN [LocaleResourceKey] AS KY ON ST.LocaleResourceKey_Id = KY.Id"
                                      + "  WHERE ST.[Language_Id] = @Language_Id";

                    Cmd.AddParameters("Language_Id", id);

                    data = Cmd.FindAll();
                }

                var lang = new Dictionary <string, string>();
                foreach (DataRow it in data.Rows)
                {
                    lang.Add(it["Name"].ToString(), it["ResourceValue"].ToString());
                }

                try
                {
                    Alllang.Add(Lang_Id, lang);
                }
                catch { }
            }

            return(Alllang[id]);
        }
Esempio n. 20
0
        private void CreateSlug(Topic topic)
        {
            var slug = ServiceHelpers.CreateUrl(topic.Name);

            if (!TestSlug(topic.Slug, slug))
            {
                var tmpSlug = slug;

                var Cmd = _context.CreateCommand();
                Cmd.CommandText = "SELECT Slug FROM [Topic] WHERE [Slug] LIKE @Slug AND [Id] != @Id ";

                Cmd.AddParameters("Id", topic.Id);
                Cmd.AddParameters("Slug", string.Concat(slug, "%"));

                DataTable data = Cmd.FindAll();
                Cmd.Close();

                int i = 0;
                while (!CheckSlug(tmpSlug, data))
                {
                    i++;
                    tmpSlug = string.Concat(slug, "-", i);
                }

                topic.Slug = tmpSlug;
            }
        }
Esempio n. 21
0
        public void Add(Language language)
        {
            var existingLanguage = GetLanguageByLanguageCulture(language.LanguageCulture);

            if (existingLanguage != null)
            {
                throw new LanguageOrCultureAlreadyExistsException(
                          $"There is already a language defined for language-culture '{existingLanguage.LanguageCulture}'");
            }

            var Cmd = _context.CreateCommand();

            Cmd.CommandText = "INSERT INTO [dbo].[Language]([Id],[Name],[LanguageCulture],[FlagImageFileName],[RightToLeft])"
                              + " VALUES(@Id,@Name,@LanguageCulture,@FlagImageFileName,@RightToLeft)";


            Cmd.Parameters.Add("Id", SqlDbType.UniqueIdentifier).Value = language.Id;
            Cmd.AddParameters("Name", language.Name);
            Cmd.AddParameters("LanguageCulture", language.LanguageCulture);
            Cmd.AddParameters("FlagImageFileName", language.FlagImageFileName);
            Cmd.AddParameters("RightToLeft", language.RightToLeft);


            bool rt = Cmd.command.ExecuteNonQuery() > 0;

            Cmd.cacheStartsWithToClear(CacheKeys.Localization.StartsWith);
            Cmd.Close();

            if (!rt)
            {
                throw new Exception("Add Language false");
            }
        }