public HttpResponseMessage Add(OfficeHourAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            ItemResponse<int> response = new ItemResponse<int>();
            string userId = UserService.GetCurrentUserId();
            response.Item = _officeHourServices.Add(model, userId);

            return Request.CreateResponse(response);
        }
Example #2
0
        private async Task <HttpResponseMessage> SendEmail(OfficeHourAddRequest model)
        {
            ItemsResponse <UserSection> EmailList = new ItemsResponse <UserSection>();

            EmailList.Items = _officeHourServices.GetEmailList(model.SectionId);

            SucessResponse sent = new SucessResponse();

            foreach (var items in EmailList.Items)
            {
                await _messagingService.SendAddOfficeHourEmail(items.Email, model);
            }
            return(Request.CreateResponse(sent));
        }
Example #3
0
        public HttpResponseMessage Add(OfficeHourAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            ItemResponse <int> response = new ItemResponse <int>();
            string             userId   = UserService.GetCurrentUserId();

            response.Item = _officeHourServices.Add(model, userId);

            return(Request.CreateResponse(response));
        }
Example #4
0
        public async Task SendAddOfficeHourEmail(string Email, OfficeHourAddRequest model)
        {
            string SubjectMessage = null;
            string BodyMessage    = null;

            if (model is OfficeHourUpdateRequest)
            {
                SubjectMessage = "There is an update on the Question and Answer Session";
                BodyMessage    = "Please be informed that there has been changes on the Question and Answer Session for " + model.Topic +
                                 " , on " + model.Date + " from " + model.StartTime + " to " + model.EndTime +
                                 ". Please check changes for " + model.Topic + ".";
            }
            else if (model is OfficeHourAddRequest)
            {
                SubjectMessage = "A new Question and Answer Session has been scheduled";
                BodyMessage    = "Please be informed that a new Question and Answer Session has been created for " + model.Topic +
                                 " , on " + model.Date + " from " + model.StartTime + " to " + model.EndTime +
                                 ". Please add your questions for " + model.Topic + ".";
            }

            SendGridMessage myMessage = new SendGridMessage();

            myMessage.AddTo(Email);
            myMessage.From = new MailAddress(_siteAdminEmailAddress, "Sabio Team");

            myMessage.Subject = SubjectMessage;

            string path     = HttpContext.Current.Server.MapPath("~/Template/OfficeHourQuestionAndAnswerSession.html");
            string contents = File.ReadAllText(path);

            contents = contents.Replace("<%body%>", BodyMessage);

            contents = contents.Replace("{{domain}}", "http://corbulo.biz/");

            myMessage.Html = contents;

            await SendAsync(myMessage);
        }
Example #5
0
        //public HttpResponseMessage Add(OfficeHourAddRequest model)
        public async Task <HttpResponseMessage> Add(OfficeHourAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            ItemResponse <int> response = new ItemResponse <int>();
            string             userId   = UserService.GetCurrentUserId();

            response.Item = _officeHourServices.Add(model, userId);

            await SendEmail(model);

            //ItemsResponse<UserSection> EmailList = new ItemsResponse<UserSection>();
            //EmailList.Items = _officeHourServices.GetEmailList(model.SectionId);

            //foreach (var items in EmailList.Items)
            //{
            //    await _messagingService.SendAddOfficeHourEmail(items.Email, model);
            //}

            return(Request.CreateResponse(response));
        }
        public int Add(OfficeHourAddRequest model, string userId)
        {
            var id    = 0;
            var ohqId = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.OfficeHours_Insert",
                                         inputParamMapper : delegate(SqlParameterCollection addParameterCollection)
            {
                addParameterCollection.AddWithValue("@InstructorId", model.InstructorId);
                addParameterCollection.AddWithValue("@Date", model.Date);
                addParameterCollection.AddWithValue("@StartTime", model.StartTime);
                addParameterCollection.AddWithValue("@EndTime", model.EndTime);
                addParameterCollection.AddWithValue("@TimeZone", model.TimeZone);
                addParameterCollection.AddWithValue("@Topic", model.Topic);
                addParameterCollection.AddWithValue("@Instructions", model.Instructions);
                addParameterCollection.AddWithValue("@SectionId", model.SectionId);
                addParameterCollection.AddWithValue("@UserId", userId);

                SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int)
                {
                    Direction = System.Data.ParameterDirection.Output
                };
                addParameterCollection.Add(p);
            },
                                         returnParameters : delegate(SqlParameterCollection para)
            {
                int.TryParse(para["@Id"].Value.ToString(), out id);
            }
                                         );

            if (model.Questions != null)
            {
                foreach (var Question in model.Questions)
                {
                    DataProvider.ExecuteNonQuery(GetConnection, "dbo.OfficeHourQuestions_Insert",
                                                 inputParamMapper : delegate(SqlParameterCollection parameterCollection)
                    {
                        parameterCollection.AddWithValue("@UserId", userId);
                        parameterCollection.AddWithValue("@OfficeHourId", id);
                        parameterCollection.AddWithValue("@Question", Question.Question);
                        parameterCollection.AddWithValue("@Response", Question.Response);
                        parameterCollection.AddWithValue("@Grouping", Question.Grouping);
                        parameterCollection.AddWithValue("@QuestionStatusId", Question.QuestionStatusId);

                        SqlParameter q = new SqlParameter("@Id", System.Data.SqlDbType.Int)
                        {
                            Direction = System.Data.ParameterDirection.Output
                        };
                        parameterCollection.Add(q);
                    },
                                                 returnParameters : delegate(SqlParameterCollection para)
                    {
                        int.TryParse(para["@Id"].Value.ToString(), out ohqId);
                    }
                                                 );
                }

                foreach (var Question in model.Questions)
                {
                    if (Question.Tag != null)
                    {
                        foreach (var TagId in Question.Tag)
                        {
                            DataProvider.ExecuteNonQuery(GetConnection, "dbo.OfficeHourQuestionTags_Insert",
                                                         inputParamMapper : delegate(SqlParameterCollection parameter)
                            {
                                parameter.AddWithValue("@OfficeHourQuestionId", ohqId);
                                parameter.AddWithValue("@TagId", TagId);
                            });
                        }
                    }
                }
            }
            return(id);
        }
Example #7
0
        public int Add(OfficeHourAddRequest model, string userId)
        {
            var id = 0;
            var ohqId = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.OfficeHours_Insert",
                inputParamMapper: delegate(SqlParameterCollection addParameterCollection)
                {
                    addParameterCollection.AddWithValue("@InstructorId", model.InstructorId);
                    addParameterCollection.AddWithValue("@Date", model.Date);
                    addParameterCollection.AddWithValue("@StartTime", model.StartTime);
                    addParameterCollection.AddWithValue("@EndTime", model.EndTime);
                    addParameterCollection.AddWithValue("@TimeZone", model.TimeZone);
                    addParameterCollection.AddWithValue("@Topic", model.Topic);
                    addParameterCollection.AddWithValue("@Instructions", model.Instructions);
                    addParameterCollection.AddWithValue("@SectionId", model.SectionId);
                    addParameterCollection.AddWithValue("@UserId", userId);

                    SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int)
                    {
                        Direction = System.Data.ParameterDirection.Output
                    };
                    addParameterCollection.Add(p);
                },
                returnParameters: delegate(SqlParameterCollection para)
                {
                    int.TryParse(para["@Id"].Value.ToString(), out id);
                }
                );

            if (model.Questions != null)
            {
                foreach (var Question in model.Questions)
                    DataProvider.ExecuteNonQuery(GetConnection, "dbo.OfficeHourQuestions_Insert",
                        inputParamMapper: delegate(SqlParameterCollection parameterCollection)
                        {
                            parameterCollection.AddWithValue("@UserId", userId);
                            parameterCollection.AddWithValue("@OfficeHourId", id);
                            parameterCollection.AddWithValue("@Question", Question.Question);
                            parameterCollection.AddWithValue("@Response", Question.Response);
                            parameterCollection.AddWithValue("@Grouping", Question.Grouping);
                            parameterCollection.AddWithValue("@QuestionStatusId", Question.QuestionStatusId);

                            SqlParameter q = new SqlParameter("@Id", System.Data.SqlDbType.Int)
                            {
                                Direction = System.Data.ParameterDirection.Output
                            };
                            parameterCollection.Add(q);
                        },
                    returnParameters: delegate(SqlParameterCollection para)
                    {
                        int.TryParse(para["@Id"].Value.ToString(), out ohqId);
                    }
                    );

                foreach (var Question in model.Questions)
                    if (Question.Tag != null)
                    {
                        foreach (var TagId in Question.Tag)
                            DataProvider.ExecuteNonQuery(GetConnection, "dbo.OfficeHourQuestionTags_Insert",
                                inputParamMapper: delegate(SqlParameterCollection parameter)
                                {
                                    parameter.AddWithValue("@OfficeHourQuestionId", ohqId);
                                    parameter.AddWithValue("@TagId", TagId);
                                });
                    }
            }
            return id;
        }