Esempio n. 1
0
        // PUT api/File/5
        public HttpResponseMessage PutFile(int id, CourseAider.Models.File file)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != file.Id)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(file).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Esempio n. 2
0
        public ActionResult Details(string dummy, int id = 0)
        {
            Course course = db.Courses.Find(id);

            if (course == null)
            {
                return(HttpNotFound());
            }
            var profile = db.UserProfiles.FirstOrDefault(p => p.UserName == WebSecurity.CurrentUserName);

            if (!course.Members.Any(member => member.UserName == profile.UserName))
            {
                course.Members.Add(profile);
            }
            db.SaveChanges();

            return(View(course));
        }
Esempio n. 3
0
 public string Post(int id)
 {
     using (var a = new CourseAiderContext())
     {
         var file = a.Files.Find(id);
         if (file != null)
         {
             if (file.Score == 0)
             {
                 file.Score          += 1;
                 file.Uploader.Score += 1;
                 a.SaveChanges();
             }
         }
     }
     return("");
 }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (CourseAiderContext db = new CourseAiderContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Esempio n. 5
0
        public void AnswerQuestion(string questionId, int answer)
        {
            if (!this.Context.User.Identity.IsAuthenticated)
            {
                return;
            }

            questions = questions.Where(q => q.Value.ExpirationTime > DateTime.Now).ToDictionary(a => a.Key, a => a.Value);
            if (questions.ContainsKey(questionId))
            {
                var question = questions[questionId];
                if (question.Answerers.Contains(this.Context.User.Identity.Name))
                {
                    return;
                }
                question.Answerers.Add(this.Context.User.Identity.Name);
                if (answer == question.CorrectAnswer)
                {
                    using (var db = new CourseAiderContext())
                    {
                        var user = db.UserProfiles.FirstOrDefault(a => a.UserName == this.Context.User.Identity.Name);
                        if (user == null)
                        {
                            return;
                        }
                        user.Score += question.Points;
                        db.SaveChanges();
                    }
                    Clients.Caller.notify("You have answered correctly");
                }
                else
                {
                    Clients.Caller.notify("You have answered incorrectly , the correct answer was '"
                                          + question.Answers[question.CorrectAnswer] + "'.");
                }
            }
        }