コード例 #1
0
        public void Edit(CompanyModel companyModel)
        {
            try
            {
                Company company = dbContext.Companies.Where(x => x.Id == companyModel.Id).FirstOrDefault();

                if (company == null)
                {
                    base.HandleError(companyModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound);
                    return;
                }

                if (Validate(companyModel))
                {
                    return;
                }

                CompanyMapper.Map(dbContext, companyModel, company);

                base.SaveChanges();

                companyModel.AddSuccess(Resources.CompanyUpdatedSuccessfully, LookUps.SuccessType.Full);
            }
            catch (Exception ex)
            {
                base.HandleError(companyModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }
コード例 #2
0
        public void Delete(CompanyModel companyModel)
        {
            try
            {
                if (ValidateDelete(companyModel))
                {
                    return;
                }

                Company company = dbContext.Companies.Where(x => x.Id == companyModel.Id).FirstOrDefault();

                if (company == null)
                {
                    base.HandleError(companyModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound);
                    return;
                }

                dbContext.Companies.Remove(company);

                base.SaveChanges();

                companyModel.AddSuccess(Resources.CompanyDeletedSuccessfully, LookUps.SuccessType.Full);
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                base.HandleError(companyModel, CommonLayer.LookUps.ErrorType.Business, null, Resources.RefrenceDeleteError);
                base.UndoUpdates();
            }
            catch (Exception ex)
            {
                base.HandleError(companyModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }
コード例 #3
0
        public void Create(CompanyModel companyModel)
        {
            try
            {
                if (Validate(companyModel))
                {
                    return;
                }

                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        Company company = new Company();
                        CompanyMapper.Map(dbContext, companyModel, company);

                        company.Id = Guid.NewGuid().ToString();

                        dbContext.Companies.Add(company);

                        base.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }

                    companyModel.AddSuccess(Resources.CompanyAddedSuccessfully, LookUps.SuccessType.Full);
                }
            }
            catch (Exception ex)
            {
                base.HandleError(companyModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }