Exemplo n.º 1
0
        public ActionResult Create(PUEvent puEvent)
        {
            ApplicationUserManager userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var userid = User.Identity.GetUserId();
            int userID = 0;

            Int32.TryParse(userid, out userID);
            if (ModelState.IsValid)
            {
                try
                {
                    PetUniverseUser current = _userManager.getUserByEmail(Membership.GetUser().Email);
                    puEvent.Status      = "PendingApproval";
                    puEvent.DateCreated = DateTime.Now;
                    puEvent.BannerPath  = "default.png";
                    puEvent.CreatedByID = userID;
                    puEvent.EventID     = _eventManager.AddEvent(puEvent);
                    if (puEvent.EventID != 0)
                    {
                        Request request = new Request()
                        {
                            DateCreated      = DateTime.Now,
                            Open             = true,
                            RequestingUserID = puEvent.CreatedByID,
                            RequestTypeID    = "Event"
                        };
                        request.RequestID = _eventManager.AddRequest(request);
                        if (request.RequestID != 0)
                        {
                            EventRequest eventRequest = new EventRequest()
                            {
                                Active           = true,
                                DateCreated      = DateTime.Now,
                                EventID          = puEvent.EventID,
                                Open             = request.Open,
                                RequestID        = request.RequestID,
                                RequestingUserID = request.RequestingUserID,
                                RequestTypeID    = request.RequestTypeID
                            };

                            _eventManager.AddEventRequest(eventRequest);
                        }
                    }

                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View());
                }
            }

            ViewBag.EventTypes = _eventTypes;
            return(View(puEvent));
        }
Exemplo n.º 2
0
        /// <summary>
        /// CREATOR: Steve Coonrod, Matt Deaton
        /// CREATED 2/10/2020
        /// APPROVER: Ryan Morganti
        ///
        /// Main Click Event to submit an Event. Submits Form Data for processing.
        ///
        /// </summary>
        /// <remarks>
        ///
        /// UPDATER: NA
        /// UPDATED: NA
        /// UPDATE: NA
        ///
        /// </remarks>
        private void BtnSubmitCreate_Click(object sender, RoutedEventArgs e)
        {
            int eventID;   //Will be returned with the Event
            int requestID; //Will be returned with the Request


            //This method will validate the field data and return the values in a string array
            //The validated field data strings will be assigned to a new Event Object
            //To be passed to the DB through the eventManager interface
            string[] validatedFieldData = validateFormData();
            if (validatedFieldData != null)
            {
                try
                {
                    //Create an Event object from the validated fields
                    PUEvent newEvent = new PUEvent()
                    {
                        CreatedByID   = Int32.Parse(validatedFieldData[0]),
                        DateCreated   = DateTime.Parse(validatedFieldData[1]),
                        EventName     = validatedFieldData[2],
                        EventTypeID   = validatedFieldData[3],
                        EventDateTime = DateTime.Parse(validatedFieldData[4]),
                        Address       = validatedFieldData[5],
                        City          = validatedFieldData[6],
                        State         = validatedFieldData[7],
                        Zipcode       = validatedFieldData[8],
                        BannerPath    = validatedFieldData[9],
                        Status        = validatedFieldData[10],
                        Description   = validatedFieldData[11]
                    };

                    //Check the User's Role

                    //In any case, the event is created...
                    //But a DC will create one with the status Approved, and will not need to create a request
                    if (_user.PURoles.Contains("Donation Coordinator"))
                    {
                        newEvent.Status = (statusOptions.Approved.ToString());
                        eventID         = _eventManager.AddEvent(newEvent);
                        if (eventID != 0)
                        {
                            MessageBox.Show("Event: " + newEvent.EventName + "\n"
                                            + "has been created.");
                        }
                    }
                    else // If the user does not have the Donation Coordinator Role...
                    {
                        newEvent.Status = (statusOptions.PendingApproval.ToString());
                        eventID         = _eventManager.AddEvent(newEvent);
                        if (eventID != 0)
                        {
                            //Create A Request
                            Request newRequest = new Request()
                            {
                                DateCreated      = DateTime.Now,
                                RequestTypeID    = "Event",
                                RequestingUserID = _user.PUUserID,
                                Open             = true
                            };
                            requestID = _eventManager.AddRequest(newRequest);
                            if (requestID != 0)
                            {
                                //Will need to create an eventRequest
                                EventRequest newEventRequest = new EventRequest()
                                {
                                    EventID           = eventID,
                                    RequestID         = requestID,
                                    DisapprovalReason = "",
                                    DesiredVolunteers = 0,
                                    ReviewerID        = 0,
                                    Active            = true
                                };

                                //Verify that all tables were updated
                                int rowsEffectedByAddRequestEvent =
                                    _eventManager.AddEventRequest(newEventRequest);
                                if (rowsEffectedByAddRequestEvent == 1 &&
                                    eventID != 0 &&
                                    requestID != 0)
                                {
                                    MessageBox.Show("Event: " + newEvent.EventName
                                                    + " has been created. \nA request has been made to review this event.");
                                    _eventMgmt.frAllEvents.Content      = new ListAllEvents(_eventManager, _eventMgmt);
                                    _eventMgmt.frPendingEvents.Content  = new ListPendingEvents(_eventManager, _eventMgmt);
                                    _eventMgmt.frApprovedEvents.Content = new ListApprovedEvents(_eventManager, _eventMgmt);
                                    CloseThisPage();
                                }
                                else
                                {
                                    MessageBox.Show("An unknown error has occurred.\nPlease try again later.");
                                    _eventManager.DeleteEvent(eventID);
                                    CloseThisPage();
                                }
                            }
                        } //End if for non-DC member Event creation
                    }     //End if-else for role-based implementation
                }         //End try
                catch (Exception ex)
                {
                    MessageBox.Show("We're Sorry.\n" +
                                    "There was an error with the process.\n" +
                                    "Please try again later.\n" + ex.Message);
                    CloseThisPage();
                }
            } //End if(validatedFieldData[] != null)
        }     //End Submit click event