Ejemplo n.º 1
0
        public async Task <string> GetRespondentsConfirmationRequest()
        {
            string userName = Request.Params["user"];
            string password = Request.Params["password"];

            var user = await db.Users.Where(u => (u.UserName == userName) && (u.Password == password)).Include("Groups.Respondents").FirstOrDefaultAsync();

            string[] data = Request.Params["respondents"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < data.Length; i++)
            {
                string[] respondentData = data[i].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                int      serverId       = int.Parse(respondentData[1]);
                int      clientId       = int.Parse(respondentData[0]);

                Respondent respondent = db.Respondents.First(r => r.Id == serverId);

                if (respondent.IsModified)
                {
                    respondent.ClientId        = clientId;
                    respondent.IsModified      = false;
                    db.Entry(respondent).State = EntityState.Modified;
                }
            }

            //var ans = db.Groups.Include("Quizs");

            await db.SaveChangesAsync();

            return("Ok");
        }
        public async Task <IHttpActionResult> PutGroup(int id, Group group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != group.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroupExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Create([Bind(Include = "Id,RespondentNumber,FirstName,LastName,IsModified,IsDeleted")] Respondent respondent)
        {
            if (ModelState.IsValid)
            {
                respondent.IsModified = true;
                db.Respondents.Add(respondent);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(respondent));
        }
        private async Task <ActionResult> AddQuiz(Quiz quiz)
        {
            if (ModelState.IsValid)
            {
                db.Entry(quiz).State = EntityState.Added;


                quiz.AnswerText = Quiz.SerializeAnswers(quiz.Questions.ToList());

                foreach (var q in quiz.Questions)
                {
                    db.Entry(q).State = EntityState.Added;
                    foreach (var a in q.Answers)
                    {
                        db.Entry(a).State = EntityState.Added;
                    }
                }

                User user = await db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefaultAsync();

                user.Quizs.Add(quiz);

                db.Entry(user).State = EntityState.Modified;
                db.Quizes.Add(quiz);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(quiz));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,GroupName,IsModified,IsDeleted")] Group group)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefaultAsync();

                group.IsModified = true;

                user.Groups.Add(group);
                db.Entry(user).State = EntityState.Modified;

                db.Groups.Add(group);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(group));
        }