Ejemplo n.º 1
0
        // GET: Proposal/Create
        public ActionResult Create()
        {
            var fields      = db.Fields.ToList();
            var supervisors = db.Supervisor.ToList();
            var viewModel   = new ProposalIdeaFieldViewModel
            {
                AllFields     = fields,
                AllSupervisor = supervisors
            };

            /* var fieldsSupervisorData = new ProposalIdeaFieldViewModel
             * {
             *   AllFields = db.Fields.Select(c => new SelectListItem
             *   {
             *       Value = c.recordID.ToString(),
             *       Text = c.field
             *
             *   }),
             *   AllSupervisor = db.Supervisor.Select(c => new SelectListItem
             *   {
             *       Value = c.User.firstName + " " + c.User.lastName,
             *       Text = c.User.firstName + " " + c.User.lastName
             *
             *   })
             * };*/

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        // GET: Proposal/Create
        public ActionResult Create()
        {
            if (IsLoggedIn() && IsAuthorized())
            {
                int userID = GetUserID();

                var user        = db.User.Where(u => u.recordID == userID).FirstOrDefault();
                var student     = db.Student.Where(s => s.recordID == userID).FirstOrDefault();
                var ticket      = db.Ticket.Where(t => t.Contributors.Any(c => c.User.recordID == userID)).FirstOrDefault();
                var idea        = db.Idea.Where(i => i.User.recordID != userID).ToList();
                var fields      = db.Fields.ToList();
                var supervisors = db.Supervisor.ToList();
                var studentUser = new ProposalIdeaFieldViewModel
                {
                    user           = user,
                    student        = student,
                    ticket         = ticket,
                    availableIdeas = idea,
                    AllFields      = fields,
                    AllSupervisor  = supervisors
                };

                if (student.matrikelNumber == 0)
                {
                    ViewBag.IsDataSet = false;
                }

                return(View(studentUser));
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
        }
Ejemplo n.º 3
0
        // GET: Proposal/Create
        public ActionResult Create(int?id)
        {
            if (IsLoggedIn() && IsAuthorized())
            {
                int userID = GetUserID();

                var user        = db.User.Where(u => u.recordID == userID).FirstOrDefault();
                var idea        = db.Idea.Where(i => i.User.recordID != userID).ToList();
                var fields      = db.Fields.ToList();
                var supervisors = db.Supervisor.ToList();

                ProposalIdeaFieldViewModel viewModel = null;
                if (id != null)
                {
                    var thisIdea = db.Idea.Where(i => i.recordID == id).FirstOrDefault();
                    //To get field name
                    int fieldID = Convert.ToInt32(thisIdea.field);
                    var field   = db.Fields.Where(f => f.recordID == fieldID).FirstOrDefault();
                    thisIdea.field = field.field;
                    viewModel      = new ProposalIdeaFieldViewModel
                    {
                        user           = user,
                        availableIdeas = idea,
                        idea           = thisIdea,
                        AllFields      = fields,
                        AllSupervisor  = supervisors
                    };
                    ViewBag.IdeaExists = true;
                }
                else
                {
                    viewModel = new ProposalIdeaFieldViewModel
                    {
                        user           = user,
                        availableIdeas = idea,
                        AllFields      = fields,
                        AllSupervisor  = supervisors
                    };
                }

                return(View(viewModel));
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
        }
Ejemplo n.º 4
0
        public ActionResult Create(ProposalIdeaFieldViewModel proposalIdeaFieldViewModel)
        {
            try
            {
                // TODO: Add insert logic here
                using (TicketingApp db = new TicketingApp())
                {
                    proposalIdeaFieldViewModel.AllFields     = db.Fields.ToList();
                    proposalIdeaFieldViewModel.AllSupervisor = db.Supervisor.ToList();

                    int userID = GetUserID();
                    var user   = db.User.Where(u => u.recordID == userID).FirstOrDefault();
                    var idea   = new Idea
                    {
                        title       = proposalIdeaFieldViewModel.proposal.nameOfProject,
                        description = proposalIdeaFieldViewModel.proposal.abstrac,
                        type        = proposalIdeaFieldViewModel.idea.type,
                        field       = proposalIdeaFieldViewModel.idea.field,
                        User        = user
                    };
                    db.Idea.Add(idea);
                    db.SaveChanges();
                    int ideaRecordId = idea.recordID;
                    var ideaCreated  = db.Idea.Where(i => i.recordID == ideaRecordId).FirstOrDefault();
                    proposalIdeaFieldViewModel.proposal.User = user;
                    proposalIdeaFieldViewModel.proposal.Idea = ideaCreated;
                    db.Proposal.Add(proposalIdeaFieldViewModel.proposal);

                    var ticket = new Ticket
                    {
                        title         = proposalIdeaFieldViewModel.proposal.nameOfProject,
                        status        = "Pending",
                        timesRejected = 0,
                        User          = user,
                        Idea          = ideaCreated
                    };
                    db.Ticket.Add(ticket);
                    db.SaveChanges();
                    int ticketRecordId = ticket.recordID;
                    var ticketCreated  = db.Ticket.Where(t => t.recordID == ticketRecordId).FirstOrDefault();

                    string userRole    = GetUserRole();
                    var    contributor = new Contributors
                    {
                        status = "Pending",
                        role   = userRole,
                        User   = user,
                        Ticket = ticketCreated
                    };
                    db.Contributor.Add(contributor);
                    db.SaveChanges();
                    var surperUser = db.User.Where(u => u.recordID == proposalIdeaFieldViewModel.supervisor).FirstOrDefault();



                    var identifier     = surperUser.email;
                    var surperUserRole = db.RoleIdentifier
                                         .Join(db.RoleIdentifierDetails,
                                               roleIdentifier => roleIdentifier.recordID,
                                               roleIdentifierDetails => roleIdentifierDetails.RoleIdentifier.recordID,
                                               (roleIdentifier, roleIdentifierDetails) => new { RoleIdentifier = roleIdentifier, RoleIdentifierDetails = roleIdentifierDetails })
                                         .Where(roleAndDetails => identifier.Contains(roleAndDetails.RoleIdentifierDetails.identifier)).FirstOrDefault();

                    contributor.User = surperUser;
                    contributor.role = surperUserRole.RoleIdentifier.role;
                    db.Contributor.Add(contributor);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                var fields      = db.Fields.ToList();
                var supervisors = db.Supervisor.ToList();
                var viewModel   = new ProposalIdeaFieldViewModel
                {
                    AllFields     = fields,
                    AllSupervisor = supervisors
                };
                return(View(viewModel));
            }
        }
Ejemplo n.º 5
0
        public ActionResult Create(ProposalIdeaFieldViewModel proposalIdeaFieldViewModel, int?id)
        {
            if (IsLoggedIn() && IsAuthorized())
            {
                proposalIdeaFieldViewModel.AllFields     = db.Fields.ToList();
                proposalIdeaFieldViewModel.AllSupervisor = db.Supervisor.ToList();

                int  userID = GetUserID();
                var  user   = db.User.Where(u => u.recordID == userID).FirstOrDefault();
                Idea idea   = null;

                // No need to create a new idea if it already exists i.e. if a Professor has made an idea
                if (id != null)
                {
                    idea = db.Idea.Where(i => i.recordID == id).FirstOrDefault();
                    proposalIdeaFieldViewModel.proposal.nameOfProject = idea.title;
                }
                else
                {
                    idea = new Idea
                    {
                        title       = proposalIdeaFieldViewModel.proposal.nameOfProject,
                        description = proposalIdeaFieldViewModel.proposal.abstrac,
                        type        = proposalIdeaFieldViewModel.idea.type,
                        field       = proposalIdeaFieldViewModel.idea.field,
                        User        = user
                    };
                    db.Idea.Add(idea);
                    db.SaveChanges();
                }

                int ideaRecordId = idea.recordID;
                var ideaCreated  = db.Idea.Where(i => i.recordID == ideaRecordId).FirstOrDefault();
                proposalIdeaFieldViewModel.proposal.User = user;
                proposalIdeaFieldViewModel.proposal.Idea = ideaCreated;
                db.Proposal.Add(proposalIdeaFieldViewModel.proposal);

                db.SaveChanges();

                var      now          = DateTime.Now;
                DateTime date         = DateTime.Now;
                var      ticketStatus = db.TicketStatus.Where(ts => ts.ticketStatus == "Proposal Awaiting Approval").FirstOrDefault();
                var      ticket       = new Ticket
                {
                    title         = proposalIdeaFieldViewModel.proposal.nameOfProject,
                    timesRejected = 0,
                    User          = user,
                    idea          = ideaCreated,
                    creationDate  = date,
                    tickettype    = ideaCreated.type,
                    ticketStatus  = ticketStatus
                };

                db.Ticket.Add(ticket);
                db.SaveChanges();
                int ticketRecordId = ticket.recordID;
                var ticketCreated  = db.Ticket.Where(t => t.recordID == ticketRecordId).FirstOrDefault();

                string userRole    = GetUserRole();
                var    contributor = new Contributors
                {
                    status = "Pending",
                    Role   = userRole,
                    User   = user,
                    Ticket = ticketCreated
                };
                db.Contributors.Add(contributor);
                db.SaveChanges();
                var surperUser = db.User.Where(u => u.recordID == proposalIdeaFieldViewModel.supervisor).FirstOrDefault();

                var identifier     = surperUser.email;
                var surperUserRole = db.RoleIdentifier
                                     .Join(db.RoleIdentifierDetails,
                                           roleIdentifier => roleIdentifier.roleIdentifierID,
                                           roleIdentifierDetails => roleIdentifierDetails.RoleIdentifier.roleIdentifierID,
                                           (roleIdentifier, roleIdentifierDetails) => new { RoleIdentifier = roleIdentifier, RoleIdentifierDetails = roleIdentifierDetails })
                                     .Where(roleAndDetails => identifier.Contains(roleAndDetails.RoleIdentifierDetails.identifier)).FirstOrDefault();

                contributor.User = surperUser;
                contributor.Role = surperUserRole.RoleIdentifier.role;
                db.Contributors.Add(contributor);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
        }
Ejemplo n.º 6
0
        public ActionResult Create(ProposalIdeaFieldViewModel proposalIdeaFieldViewModel)
        {
            try
            {
                // TODO: Add insert logic here
                using (TicketingApp db = new TicketingApp())
                {
                    proposalIdeaFieldViewModel.AllFields     = db.Fields.ToList();
                    proposalIdeaFieldViewModel.AllSupervisor = db.Supervisor.ToList();

                    int userID1 = GetUserID();
                    var user1   = db.User.Where(u => u.recordID == userID1).FirstOrDefault();
                    var idea1   = new Idea
                    {
                        title       = proposalIdeaFieldViewModel.proposal.nameOfProject,
                        description = proposalIdeaFieldViewModel.proposal.abstrac,
                        type        = proposalIdeaFieldViewModel.idea.type,
                        field       = proposalIdeaFieldViewModel.idea.field,
                        User        = user1
                    };
                    db.Idea.Add(idea1);
                    db.SaveChanges();
                    int ideaRecordId = idea1.recordID;
                    var ideaCreated  = db.Idea.Where(i => i.recordID == ideaRecordId).FirstOrDefault();
                    proposalIdeaFieldViewModel.proposal.User = user1;
                    proposalIdeaFieldViewModel.proposal.Idea = ideaCreated;
                    db.Proposal.Add(proposalIdeaFieldViewModel.proposal);

                    var ticket1 = new Ticket
                    {
                        title         = proposalIdeaFieldViewModel.proposal.nameOfProject,
                        status        = "Pending",
                        timesRejected = 0,
                        User          = user1,
                        Idea          = ideaCreated
                    };
                    db.Ticket.Add(ticket1);
                    db.SaveChanges();
                    int ticketRecordId = ticket1.recordID;
                    var ticketCreated  = db.Ticket.Where(t => t.recordID == ticketRecordId).FirstOrDefault();

                    string userRole    = GetUserRole();
                    var    contributor = new Contributors
                    {
                        status = "Pending",
                        Role   = userRole,
                        User   = user1,
                        Ticket = ticketCreated
                    };
                    db.Contributors.Add(contributor);
                    db.SaveChanges();
                    var surperUser = db.User.Where(u => u.recordID == proposalIdeaFieldViewModel.supervisor).FirstOrDefault();



                    var identifier     = surperUser.email;
                    var surperUserRole = db.RoleIdentifier
                                         .Join(db.RoleIdentifierDetails,
                                               roleIdentifier => roleIdentifier.recordID,
                                               roleIdentifierDetails => roleIdentifierDetails.RoleIdentifier.recordID,
                                               (roleIdentifier, roleIdentifierDetails) => new { RoleIdentifier = roleIdentifier, RoleIdentifierDetails = roleIdentifierDetails })
                                         .Where(roleAndDetails => identifier.Contains(roleAndDetails.RoleIdentifierDetails.identifier)).FirstOrDefault();

                    contributor.User = surperUser;
                    contributor.Role = surperUserRole.RoleIdentifier.role;
                    db.Contributors.Add(contributor);
                    db.SaveChanges();
                }
                int userID = GetUserID();

                var user     = db.User.Where(u => u.recordID == userID).FirstOrDefault();
                var student  = db.Student.Where(s => s.recordID == userID).FirstOrDefault();
                var ticket   = db.Ticket.Where(t => t.Contributors.Any(c => c.User.recordID == userID)).FirstOrDefault();
                var idea     = db.Idea.Where(i => i.User.recordID != userID).ToList();
                var proposal = db.Proposal.Where(p => p.User.recordID == userID).ToList();

                var proposalUser = new ProposalUserViewModel
                {
                    user           = user,
                    student        = student,
                    ticket         = ticket,
                    availableIdeas = idea,
                    proposals      = proposal
                };
                return(View("Index", proposalUser));
            }
            catch
            {
            }
        }