Ejemplo n.º 1
0
        public static int Delete(Guid id, bool rollback = false)
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    DbContextTransaction transaction = null;
                    if (rollback)
                    {
                        transaction = dc.Database.BeginTransaction();
                    }
                    tblActivation updaterow = dc.tblActivations.FirstOrDefault(q => q.Id == id);

                    if (updaterow != null)
                    {
                        dc.tblActivations.Remove(updaterow);
                    }
                    else
                    {
                        throw new Exception("Row was not found");
                    }
                    if (rollback)
                    {
                        transaction.Rollback();
                    }
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
 public static int Insert(Activation activation, bool rollback = false)
 {
     try
     {
         using (SurveyEntities dc = new SurveyEntities())
         {
             DbContextTransaction transaction = null;
             if (rollback)
             {
                 transaction = dc.Database.BeginTransaction();
             }
             tblActivation newrow = new tblActivation()
             {
                 Id             = Guid.NewGuid(),
                 QuestionId     = activation.QuestionId,
                 StartDate      = activation.StartDate,
                 EndDate        = activation.EndDate,
                 ActivationCode = activation.ActivationCode
             };
             dc.tblActivations.Add(newrow);
             activation.Id = newrow.Id;
             if (rollback)
             {
                 transaction.Rollback();
             }
             return(dc.SaveChanges());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 3
0
        public int Delete()
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    //If the Id is set, get the result in the table where it matches
                    if (this.Id != Guid.Empty)
                    {
                        tblActivation activation = dc.tblActivations.Where(a => a.Id == this.Id).FirstOrDefault();

                        //If a row was retrieved, change
                        if (activation != null)
                        {
                            dc.tblActivations.Remove(activation);

                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("Could not find Activation row with this ID");
                        }
                    }
                    else
                    {
                        throw new Exception("Id not set on Activation");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public int Insert()
        {
            int result = 0;

            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    //Activation new activation and set properties
                    tblActivation activation = new tblActivation();
                    activation.Id             = Guid.NewGuid();
                    activation.EndDate        = this.EndDate;
                    activation.StartDate      = this.StartDate;
                    activation.QuestionId     = this.QuestionId;
                    activation.ActivationCode = this.ActivationCode;

                    this.Id = activation.Id;

                    //Add activation to the table
                    dc.tblActivations.Add(activation);

                    //Commit the changes
                    result = dc.SaveChanges();

                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
0
        public void LoadByQuestionId(Guid questionId)
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    tblActivation activation = dc.tblActivations.FirstOrDefault(a => a.QuestionId == questionId);

                    //If a row was retrieved, change
                    if (activation != null)
                    {
                        this.Id             = activation.Id;
                        this.EndDate        = activation.EndDate;
                        this.StartDate      = activation.StartDate;
                        this.ActivationCode = activation.ActivationCode;
                        this.QuestionId     = activation.QuestionId;
                    }
                    else
                    {
                        throw new Exception("Could not find Activation row with this ID");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 6
0
        public void DeleteTest()
        {
            using (SurveyEntities dc = new SurveyEntities())
            {
                tblActivation activation = dc.tblActivations.FirstOrDefault(a => a.ActivationCode == "updat");

                dc.tblActivations.Remove(activation);

                dc.SaveChanges();

                tblActivation retrievedActivation = dc.tblActivations.FirstOrDefault(a => a.ActivationCode == "updat");

                Assert.IsNull(retrievedActivation);
            }
        }
Ejemplo n.º 7
0
        public void InsertTest()
        {
            using (SurveyEntities dc = new SurveyEntities())
            {
                tblActivation activation = new tblActivation();
                activation.Id             = Guid.NewGuid();
                activation.StartDate      = DateTime.Now;
                activation.EndDate        = DateTime.Now.AddYears(10);
                activation.QuestionId     = dc.tblQuestions.FirstOrDefault(q => q.Text == "Who sprouts mung beans in their desk drawers?").Id;
                activation.ActivationCode = "utest";

                dc.tblActivations.Add(activation);

                dc.SaveChanges();

                tblActivation retrievedActivation = dc.tblActivations.FirstOrDefault(a => a.ActivationCode == "utest");

                Assert.AreEqual(activation.Id, retrievedActivation.Id);
            }
        }
Ejemplo n.º 8
0
        public static int Update(Activation activation, bool rollback = false)
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    DbContextTransaction transaction = null;
                    if (rollback)
                    {
                        transaction = dc.Database.BeginTransaction();
                    }
                    tblActivation updaterow = dc.tblActivations.FirstOrDefault(q => q.Id == activation.Id);

                    if (updaterow != null)
                    {
                        updaterow.QuestionId     = activation.QuestionId;
                        updaterow.StartDate      = activation.StartDate;
                        updaterow.EndDate        = activation.EndDate;
                        updaterow.ActivationCode = activation.ActivationCode;
                    }
                    else
                    {
                        throw new Exception("Row was not found");
                    }
                    if (rollback)
                    {
                        transaction.Rollback();
                    }
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 9
0
        public static Activation GetActivation(Guid questionId)
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    tblActivation row = new tblActivation();
                    row = dc.tblActivations.FirstOrDefault(q => q.QuestionId == questionId);
                    if (row == null)
                    {
                        return(null);
                    }
                    Activation activation = new Activation {
                        Id = row.Id, QuestionId = row.QuestionId, StartDate = row.StartDate, EndDate = row.EndDate, ActivationCode = row.ActivationCode
                    };

                    return(activation);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 10
0
        public void LoadById()
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    //If the Id is set, get the result in the table where it matches
                    if (this.Id != Guid.Empty)
                    {
                        tblActivation activation = dc.tblActivations.FirstOrDefault(a => a.Id == this.Id);

                        //If a row was retrieved, change
                        if (activation != null)
                        {
                            this.Id             = activation.Id;
                            this.EndDate        = activation.EndDate;
                            this.StartDate      = activation.StartDate;
                            this.ActivationCode = activation.ActivationCode;
                            this.QuestionId     = activation.QuestionId;
                        }
                        else
                        {
                            throw new Exception("Could not find Activation row with this ID");
                        }
                    }
                    else
                    {
                        throw new Exception("Id not set on Activation");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }