public bool Insert(Country country, List <CountryIPRange> list, HttpPostedFileBase file) { try { this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); this.FileManagerConnection.StartTransaction(IsolationLevel.ReadUncommitted); if (file != null) { country.Image = FileManagerComponent.Instance.FileTransactionalFacade(this.FileManagerConnection).Insert(file); } if (!new CountryBO().Insert(this.ConnectionHandler, country)) { throw new Exception("خطایی در ذخیره کشور وجود دارد"); } var countryIpRangeBo = new CountryIPRangeBO(); foreach (var countryIpRange in list) { countryIpRange.CountryId = country.Id; if (!countryIpRangeBo.Insert(this.ConnectionHandler, countryIpRange)) { throw new Exception("خطایی در ذخیره IP کشور وجود دارد"); } } this.ConnectionHandler.CommitTransaction(); this.FileManagerConnection.CommitTransaction(); return(true); } catch (KnownException ex) { this.ConnectionHandler.RollBack(); this.FileManagerConnection.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } catch (Exception ex) { this.ConnectionHandler.RollBack(); this.FileManagerConnection.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public bool Update(Country country, List <CountryIPRange> list, HttpPostedFileBase file) { try { this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); this.FileManagerConnection.StartTransaction(IsolationLevel.ReadUncommitted); if (file != null) { var fileTransactionalFacade = FileManagerComponent.Instance.FileTransactionalFacade(this.FileManagerConnection); if (country.Image.HasValue) { fileTransactionalFacade .Update(file, (Guid)country.Image); } else { country.Image = fileTransactionalFacade .Insert(file); } } var countryIpRangeBo = new CountryIPRangeBO(); var countryIpRanges = countryIpRangeBo.Where(this.ConnectionHandler, x => x.CountryId == country.Id); foreach (var countryIpRange in list) { CountryIPRange range = countryIpRange; var ipRange = countryIpRangeBo.FirstOrDefault(this.ConnectionHandler, x => x.CountryId == country.Id && x.Id == range.Id); if (ipRange == null) { countryIpRange.CountryId = country.Id; if (!countryIpRangeBo.Insert(this.ConnectionHandler, countryIpRange)) { throw new Exception("خطایی در ذخیره IP کشور وجود دارد"); } } else { if (!countryIpRangeBo.Update(this.ConnectionHandler, countryIpRange)) { throw new Exception("خطایی در ذخیره IP کشور وجود دارد"); } } } foreach (var countryIpRange in countryIpRanges) { if (list.Any(x => x.Id == countryIpRange.Id)) { continue; } if (!countryIpRangeBo.Delete(this.ConnectionHandler, countryIpRange.Id)) { throw new Exception("خطایی در حذف IP کشور وجود دارد"); } } if (!new CountryBO().Update(this.ConnectionHandler, country)) { throw new Exception("خطایی در ذخیره کشور وجود دارد"); } this.ConnectionHandler.CommitTransaction(); this.FileManagerConnection.CommitTransaction(); return(true); } catch (KnownException ex) { this.ConnectionHandler.RollBack(); this.FileManagerConnection.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } catch (Exception ex) { this.ConnectionHandler.RollBack(); this.FileManagerConnection.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }