public void ActualizarNombre(Alumno alumno)
 {
     using (var ctx = new DbContextScope())
     {
         repoAlumno.PartialUpdate(alumno, x => x.Nombre, x => x.Apellido);
         ctx.SaveChanges();
     }
 }
Exemple #2
0
        public void AddUsingAmbientDbContextScope(Company comp, User user)
        {
            using (var scope = new DbContextScope(DbContextScopePurpose.Writing))
            {
                this.repoComp.Insert(comp);
                user.Company = comp;
                this.repoUser.Insert(user);

                scope.SaveChanges();
            }
        }
        public ResponseModel Eliminar(int id)
        {
            using (var ctx = new DbContextScope())
            {
                repoAlumno.PartialUpdate(new Alumno {
                    id = id, Eliminado = true
                }, x => x.Eliminado);
                ctx.SaveChanges();

                rm.SetResponse(true);
                return(rm);
            }
        }
 public void InsertarVarios(List <Alumno> alumnos)
 {
     using (var ctx = new DbContextScope())
     {
         using (DbContextScope.DbContext.Database.BeginTransaction())
         {
             try
             {
                 repoAlumno.Insert(alumnos);
                 ctx.SaveChanges();
             }
             catch (Exception)
             {
             }
         }
     }
 }
        public ResponseModel Guardar(Alumno alumno)
        {
            using (var ctx = new DbContextScope())
            {
                if (alumno.id == 0)
                {
                    repoAlumno.Insert(alumno);
                }
                else
                {
                    repoAlumno.Update(alumno);
                }

                ctx.SaveChanges();

                rm.SetResponse(true);
                return(rm);
            }
        }
Exemple #6
0
        public int AddCampaign(Model.EF.Campaign campaign, AccountUser user)
        {
            //Updated by Action_Chen 20150805
            //EventHandling & Logger框架程式範例
            var baseLogger = new _BaseLogger();

            //Updated by Action_Chen 20150805
            //EventHandling & Logger框架程式範例
            try
            {
                using (var scope = new DbContextScope(DbContextScopePurpose.Writing))
                {
                    campaign.DateCreated = DateTime.Now;
                    campaign.DateModified = campaign.DateCreated;
                    this.RepoCampaign.Insert(campaign);
                    scope.SaveChanges();
                }

            }

            //Updated by Action_Chen 20150805
            //EventHandling & Logger框架程式範例

            //catch (DbUpdateException ex)
            catch (Exception ex)
            {
                //throw new MigoDbUpdateException();
                throw new MigoCommitFailedException(user);
            }

            return campaign.CampaignID;
        }
Exemple #7
0
 private void DeleteCampaignTagMapping(int id)
 {
     using (var scope = new DbContextScope(DbContextScopePurpose.Writing))
     {
         this.RepoCampaignTagInfo.DeleteByID(id);
         scope.SaveChanges();
     }
 }
Exemple #8
0
 public void UpdateCampaign(Model.EF.Campaign campaign, int company_id)
 {
     this.CheckIsEqualCompany(company_id, campaign.CampaignID);
     using (var scope = new DbContextScope(DbContextScopePurpose.Writing))
     {
         campaign.DateModified = DateTime.Now;
         this.RepoCampaign.Update(campaign);
         scope.SaveChanges();
     }
 }
Exemple #9
0
        public void DeleteCampaign(int campaign_id, int company_id)
        {
            this.CheckIsEqualCompany(company_id, campaign_id);
            using (var scope = new DbContextScope(DbContextScopePurpose.Writing))
            {
                var campaign = this.GetCampaignById(campaign_id, company_id);
                campaign.CampaignTag.ToList().ForEach(q =>
                {
                    this.RepoCampaignTagInfo.DeleteByID(q.CampaignTagID);
                });

                campaign.CampaignChannel.ToList()
                    .ForEach(q =>
                    {
                        this.RepoCampaignChannelMapping.DeleteByID(q.ID);
                    });

                this.RepoSMS.Find().Where(q => q.CampaignID == campaign_id).ToList()
                    .ForEach(sms => this.RepoSMS.Delete(sms));

                this.RepoCampaignKeywordSetting.Find().Where(q => q.CampaignId == campaign_id).ToList()
                    .ForEach(keywordSetting =>
                    {
                        keywordSetting.CampaignKeywordReplaces.ToList().ForEach(keywordReplace =>
                        {
                            this.RepoCampaignKeywordReplace.Delete(keywordReplace);
                        });
                        this.RepoCampaignKeywordSetting.Delete(keywordSetting);
                    });

                this.RepoTaExportInfo.Find().Where(q => q.CampaignID == campaign_id).ToList()
                    .ForEach(taExportInfo => this.RepoTaExportInfo.Delete(taExportInfo));

                this.RepoSystemJobInfo.Find().Where(q => q.CampaignID == campaign_id).ToList()
                    .ForEach(systemJobInfo => this.RepoSystemJobInfo.Delete(systemJobInfo));

                this.RepoCampaign.DeleteByID(campaign_id);

                scope.SaveChanges();
            }
        }