Beispiel #1
0
        public async Task <IActionResult> Create([Bind("Id,Code,Address")] HomeCodes homeCodes)
        {
            if (ModelState.IsValid)
            {
                _context.Add(homeCodes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(homeCodes));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,FName,Lname,Code,address")] MobileUsers mobileUsers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mobileUsers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mobileUsers));
        }
        public async Task <IActionResult> Create([Bind("id,name,service,phone_number,url")] ServiceProviderModel serviceProviderModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(serviceProviderModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(serviceProviderModel));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("Id,Title,Link,Steps,Category,Tags")] ContentModel contentModel)
        {
            if (ModelState.IsValid)
            {
                // Change YouTube link to embedded link
                String url = contentModel.Link;
                url = url.Split("v=")[1];
                url = "https://www.youtube.com/embed/" + url;
                contentModel.Link = url;

                String newTags = "";
                //if there are no tags don't try to get them from the modelstate
                if (contentModel.Tags != null)
                {
                    //Get tags from view
                    newTags = ModelState.Root.Children[1].AttemptedValue;
                }
                //Split tags into array
                String[] beforeTitle = newTags.Split(",");
                //Puncuation list, used to remove non alphanumeric characters from title
                char[] puncuation = { ' ', '.', ',', '\"', '{', '}', '[', ']', '(', ')', '<', '>' };
                //Grab title from view and split it into an array, removing characters from the puncuation list
                String[] titleTags = contentModel.Title.Split(puncuation, StringSplitOptions.RemoveEmptyEntries);
                //set all tags to lowercase
                titleTags   = titleTags.Select(s => s.ToLowerInvariant()).ToArray();
                beforeTitle = beforeTitle.Select(s => s.ToLowerInvariant()).ToArray();
                //Put the tags and title together
                String[] afterTitle = beforeTitle.Union(titleTags).ToArray();
                //if there are no tags inputed and title was noly one word
                if (afterTitle.Length <= 1)
                {
                    //set tags to the only word
                    contentModel.Tags = afterTitle[0];
                }
                else
                {
                    //Changes tags to the inputted tags + title
                    contentModel.Tags = String.Join(", ", afterTitle.Where(s => !string.IsNullOrEmpty(s)));
                }

                _context.Add(contentModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(contentModel));
        }