Exemplo n.º 1
0
        public ActionResult <Resourse> Create([FromHeaderAttribute] string Authorization, [FromBody] Resourse resourse)
        {
            if (isAuthorized(Authorization) && isUserATeacher(Authorization))
            {
                User             user;
                List <Subscribe> subscribes;
                string           message;

                subscribes = _subscribeService.GetByCourseId(resourse.CourseId);

                if (subscribes == null)
                {
                    return(NotFound());
                }

                foreach (var subscribe in subscribes)
                {
                    user = _usersService.Get(subscribe.ID_User);

                    if (user == null)
                    {
                        return(NotFound());
                    }


                    message = "S-a incarcat o noua resursa cu titlul " + resourse.Title + "\n"
                              + "Cu descrierea: " + resourse.Description + "\n"
                              + "Resursa poate fi accesata la: " + resourse.Link;



                    MailHelper.SendMail(user.Email, message);
                }

                _resourseService.Create(resourse);

                return(CreatedAtRoute("GetResourse", new { id = resourse._id.ToString() }, resourse));
            }
            else
            {
                return(Unauthorized());
            }
        }