Beispiel #1
0
        //Purpose: Adds an object 'activity' in the 'Activity' table
        //Input: 'activity' object of type 'Activity.cs'
        //Output: Returns the object 'activity' upon its successful addition in the table
        public Activity Add(Activity Act)
        {
            if (Act == null)
            {
                throw new ArgumentNullException("Activity");
            }

            // TO DO : Code to save record into database
            Db1.Activities.Add(Act);
            foreach (var question in Act.Questions)
            {
                question.activity_id = Act.id;
                Db1.Questions.Add(question);
                foreach (var answer in question.Answers)
                {
                    answer.question_id = question.id;
                    answer.activity_id = question.activity_id;
                    Db1.Answers.Add(answer);
                }
            }
            if (Act.Activity_Group != null)
            {
                foreach (var group in Act.Activity_Group)
                {
                    group.activity_id = Act.id;
                    Db1.Activity_Group.Add(group);
                }
            }
            Db1.SaveChanges();
            return(Act);
        }
        public Answer Add(PollAnswerDetails answer)
        {
            if (answer == null)
            {
                throw new ArgumentNullException("answer");
            }

            try
            {
                User_Answer user_ans = new User_Answer();
                //ans.description = answer.answerDesc;
                user_ans.answer_id   = (db.Answers.Where(a => (a.description == answer.answerDesc && a.question_id == answer.questionId)).FirstOrDefault()).id;
                user_ans.user_id     = answer.userId;
                user_ans.activity_id = answer.activityId;
                user_ans.question_id = answer.questionId;

                db.User_Answer.Add(user_ans);
                db.SaveChanges();

                Answer ans = db.Answers.Where(a => a.id == user_ans.answer_id).FirstOrDefault();
                if (ans.count == null)
                {
                    ans.count = 1;
                }
                else
                {
                    ans.count = ans.count + 1;
                }
                db.SaveChanges();

                //int count = (int)db.Answers.Where(a => a.id == user_ans.answer_id).FirstOrDefault().count;
                //count = count + 1;
                //db.Answers.Select(string.Format());

                return(ans);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured: " + e.Message);
                throw e;
            }
        }
Beispiel #3
0
        //Purpose: Adds an object 'answer' in the 'Answer' table
        //Input: 'answer' object of type 'Answer.cs'
        //Output: Returns the object 'answer' upon its successful addition in the table
        public Answer Add(Answer Ans)
        {
            if (Ans == null)
            {
                throw new ArgumentNullException("Answer");
            }

            // TO DO : Code to save record into database
            Db2.Answers.Add(Ans);

            Db2.SaveChanges();
            return(Ans);
        }
        /// <summary>
        /// This method updates group details
        /// </summary>
        /// <param name="group"></param>
        /// <returns>true or false   </returns>
        public bool UpdatGroup(Group group)
        {
            db.Entry(group).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(false);
            }

            return(true);
        }
        //Purpose: Adds an object 'activity' in the 'Activity' table
        //Input: 'activity' object of type 'Activity.cs'
        //Output: Returns the object 'activity' upon its successful addition in the table
        //        If any exception occurs, the exception message is printed and the exception is thrown
        public Activity Add(ActivityGroupDetails act)
        {
            if (act == null)
            {
                throw new ArgumentNullException("activity");
            }

            try
            {
                LinkedList <Activity_Group> grps = new LinkedList <Activity_Group>();
                //Activity_Group ag = new Activity_Group();
                if (act.Groups != null)
                {
                    foreach (Group g in act.Groups)
                    {
                        Activity_Group ag = new Activity_Group();
                        ag.group_id = (db.Groups.Where(group => group.name == g.name).FirstOrDefault()).id;
                        grps.AddLast(ag);
                        //grps.Add(ag);
                    }
                }

                Activity activity = new Activity();
                activity.heading        = act.heading;
                activity.description    = act.description;
                activity.type           = act.type;
                activity.category       = act.category;
                activity.createdby      = act.createdby;
                activity.Questions      = act.Questions;
                activity.Answers        = act.Answers;
                activity.Activity_Group = grps;
                db.Activities.Add(activity);
                db.SaveChanges();


                return(activity);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured: " + e.Message);
                throw e;
            }
        }
        //Purpose: Adds the user
        //Input: 'user' for the Add method
        //Output:

        //        In case of 'null' input, the method throws 'ArgumentNullException'
        //        ELSE adds user and saves the changes and returns the output as the user
        public User Add(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            objEntities.Users.Add(user);
            objEntities.SaveChanges();
            return(user);
        }
Beispiel #7
0
        public dynamic RequestGroupLeaderShip(GroupLeaderShipInput request)
        {
            User_Request objUserRequest = new User_Request();

            objUserRequest.description = request.description;
            objUserRequest.user_id     = request.userId;
            var userRequestSubmitted = objEntities.User_Request.Where(item => item.user_id == request.userId).ToList();

            if (userRequestSubmitted.Count() != 0)
            {
                return(null);
            }
            var result = objEntities.User_Request.Add(objUserRequest);

            objEntities.SaveChanges();
            if (result == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        //Purpose: Adds an object 'question' in the 'Question' table
        //Input: 'question' object of type 'Question.cs'
        //Output: Returns the object 'question' upon its successful addition in the table
        //        If any exception occurs, the exception message is printed and the exception is thrown
        public Question Add(Question question)
        {
            if (question == null)
            {
                throw new ArgumentNullException("question");
            }

            try
            {
                db.Questions.Add(question);
                db.SaveChanges();
                return(question);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured: " + e.Message);
                throw e;
            }
        }