Exemplo n.º 1
0
        //Updates the Posting types on edit
        private void UpdatePostingTypes(string[] selectedTypes, Posting postingToUpdate)
        {
            if (selectedTypes == null)
            {
                postingToUpdate.Posting_PostingTypes = new List <Posting_PostingType>();
                return;
            }

            var selectedTypesHS = new HashSet <string>(selectedTypes);
            var postingTypes    = new HashSet <int>
                                      (postingToUpdate.Posting_PostingTypes.Select(c => c.PostingTypes.PostingTypeID));

            foreach (var type in _context.PostingTypes)
            {
                if (selectedTypesHS.Contains(type.PostingTypeID.ToString()))
                {
                    if (!postingTypes.Contains(type.PostingTypeID))
                    {
                        postingToUpdate.Posting_PostingTypes.Add(new Posting_PostingType {
                            PostingID = postingToUpdate.PostingID, PostingTypeID = type.PostingTypeID
                        });
                    }
                }
                else
                {
                    if (postingTypes.Contains(type.PostingTypeID))
                    {
                        Posting_PostingType typeToRemove = postingToUpdate.Posting_PostingTypes.FirstOrDefault(i => i.PostingTypeID == type.PostingTypeID);
                        _context.Remove(typeToRemove);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("PostingID,Description,PostingFor,PostingTitle, HidePosting, SharableToTeam, ApplicationURL, ApplicationDeadline, Location")] Posting posting, string[] selectedTypes)
        {
            if (selectedTypes != null)
            {
                posting.Posting_PostingTypes = new List <Posting_PostingType>();
                foreach (var type in selectedTypes)
                {
                    var typesToAdd = new Posting_PostingType {
                        PostingID = posting.PostingID, PostingTypeID = int.Parse(type)
                    };
                    posting.Posting_PostingTypes.Add(typesToAdd);
                }
            }
            if (ModelState.IsValid)
            {
                var currentUser = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                if (currentUser == null)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                var thisUser = await _context.User
                               .FirstOrDefaultAsync(m => m.Id == currentUser);

                posting.PostingOwner = thisUser;

                var postingURL = posting.ApplicationURL.ToLower();
                if (!postingURL.Contains("constellation.citwdd.net") && !(postingURL.Contains("http://") || postingURL.Contains("https://")))
                {
                    posting.ApplicationURL = "http://" + posting.ApplicationURL;
                    _context.Add(posting);
                }

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

                return(RedirectToAction("Edit", "Postings", new { id = posting.PostingID }));
            }
            PopulateAssignedTypeData(posting);
            return(RedirectToAction("Edit", "Postings", new { id = posting.PostingID }));
        }