Exemplo n.º 1
0
        public ActionResult AcceptCoachRequest(long requestID)
        {
            String     result  = "Coach permission added.";
            DBAccessor dba     = new DBAccessor();
            Request    request = dba.GetRequest(requestID, RequestType.COACH_PERMISSION);

            if (request != null)
            {
                if (dba.AddCoachPermission(request.requestee.ID))
                {
                    // Form an email
                    MailMessage newMessage  = new MailMessage();
                    SmtpClient  mailService = new SmtpClient();

                    //set the addresses
                    newMessage.From = new MailAddress(AppConstants.EMAIL_ADMIN);
                    newMessage.To.Add(request.requestee.email);

                    //set the content
                    newMessage.Subject = "Coach Permission Approved";
                    newMessage.Body    = "Your request to receive coach permission at dugoutdigits.com has been approved.";

                    //send the message
                    mailService.UseDefaultCredentials = false;
                    mailService.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    mailService.Host        = AppConstants.EMAIL_SMTP_ADDRESS;
                    mailService.Credentials = new NetworkCredential(AppConstants.EMAIL_SMTP_USERNAME, AppConstants.EMAIL_SMTP_PASSWORD);
                    mailService.Send(newMessage);

                    // Remove the request from the DB
                    if (!dba.RemoveRequest(request.ID))
                    {
                        result = "Error removing the coach request from the database (ID=" + request.ID + ").";
                    }
                }
                else
                {
                    result = "Error adding coach permission.";
                }
            }
            else
            {
                result = "The request couldn't be found in the database.";
            }

            return(Json(
                       new { message = result },
                       JsonRequestBehavior.AllowGet
                       ));
        }