Exemplo n.º 1
0
        public static void AddToDatabase(string url, string content)
        {
            context = Data.Context;

            string[] tokens = WebUtility.UrlDecode(content).Split('&');

            if (Regex.IsMatch(url, @"^/contacts.html"))
            {
                if (tokens.Length < 3)
                {
                    throw new ArgumentException();
                }

                var    message     = new Message();
                string senderEmail = tokens[0].Split('=')[1];
                User   sender      = context.Users.FirstOrDefault(u => u.Email == senderEmail);
                string subjectName = tokens[1].Split('=')[1];
                User   subject     = context.Users.FirstOrDefault(u => u.Username == subjectName);
                if (sender == null || subject == null)
                {
                    Console.WriteLine("Invalid email address or subject username.");
                    throw new ArgumentNullException();
                }

                message.Sender         = sender;
                message.Subject        = subject;
                message.MessageContent = tokens[2].Split('=')[1];
                context.Messages.Add(message);

                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static string GetProduct(string searhByName, string styleName)
        {
            context = Data.Context;
            StringBuilder sb          = new StringBuilder();
            var           navbarLines = StyleChenger.InsertStyle("../../content/products-navbar.html", $"../../content/css/{styleName}.css");

            sb.AppendLine(navbarLines);
            sb.AppendLine("<div class=\"row well products-info\">");

            var knives = context.Knives.Where(k => k.Name.Contains(searhByName));

            if (knives.Count() == 0)
            {
                sb.AppendLine("<h2 class=\"text-center\">There are no knifes.</h2>");
            }
            else
            {
                foreach (var knife in knives)
                {
                    CreateProductView(sb, knife);
                }
            }


            sb.AppendLine("</div>");
            var footer = File.ReadLines("../../content/products-footer.html");

            foreach (var footerLine in footer)
            {
                sb.AppendLine(footerLine);
            }

            return(sb.ToString());
        }