public static async Task InsertDefaultDataAsync() { var dbContext = new ModelContext(); var res = new ReturnedSaveFuncInfo(); #region Customer var allCusGroup = await CustomerGroupBussines.GetAllAsync(); if (allCusGroup.Count <= 0) { var cusGroup = new CustomerGroupBussines() { Guid = Guid.NewGuid(), Name = "فروشگاه اینترنتی", ParentGuid = Guid.Empty }; res.AddReturnedValue(await cusGroup.SaveAsync()); res.ThrowExceptionIfError(); } #endregion #region Rolles var allRolles = await RolleBussines.GetAllAsync(); var _roolesList = new List <RolleBussines>(); if (allRolles.Count <= 0) { var rolle1 = new RolleBussines() { Guid = Guid.NewGuid(), RolleName = "User", RolleTitle = "کاربر عادی" }; var rolle2 = new RolleBussines() { Guid = Guid.NewGuid(), RolleName = "Admin", RolleTitle = "مدیر کل سیستم" }; _roolesList.Add(rolle1); _roolesList.Add(rolle2); res.AddReturnedValue(await RolleBussines.SaveRangeAsync(_roolesList)); res.ThrowExceptionIfError(); } #endregion await dbContext.SaveChangesAsync(); dbContext.Dispose(); }
public static async Task <ReturnedSaveFuncInfo> SaveAsync(string key, string value, string tranName = "") { var res = new ReturnedSaveFuncInfo(); var autoTran = string.IsNullOrEmpty(tranName); if (autoTran) { tranName = Guid.NewGuid().ToString(); } try { if (autoTran) { //BeginTransaction } var sett = Get(key); if (sett != null) { res.AddReturnedValue(await UnitOfWork.Settings.RemoveAsync(sett.Guid, tranName)); res.ThrowExceptionIfError(); } var set = new SettingsBussines() { Guid = Guid.NewGuid(), Name = key, Value = value, Modified = DateTime.Now }; res.AddReturnedValue(await UnitOfWork.Settings.SaveAsync(set, tranName)); res.ThrowExceptionIfError(); if (autoTran) { //CommitTransAction } } catch (Exception ex) { if (autoTran) { //RollBackTransAction } WebErrorLog.ErrorInstence.StartErrorLog(ex); res.AddReturnedValue(ex); } return(res); }
public async Task <ReturnedSaveFuncInfo> SaveAsync(string tranName = "") { var res = new ReturnedSaveFuncInfo(); var autoTran = string.IsNullOrEmpty(tranName); if (autoTran) { tranName = Guid.NewGuid().ToString(); } try { if (autoTran) { //BeginTransaction } res.AddReturnedValue(await UnitOfWork.CustomerLog.SaveAsync(this, tranName)); res.ThrowExceptionIfError(); if (autoTran) { //CommitTransAction } } catch (Exception ex) { if (autoTran) { //RollBackTransAction } WebErrorLog.ErrorInstence.StartErrorLog(ex); res.AddReturnedValue(ex); } return(res); }
public static async Task <ReturnedSaveFuncInfo> SaveRangeAsync(List <PrdSelectedGroupBussines> list, string tranName = "") { var res = new ReturnedSaveFuncInfo(); var autoTran = string.IsNullOrEmpty(tranName); if (autoTran) { tranName = Guid.NewGuid().ToString(); } try { if (autoTran) { //BeginTransaction } res.AddReturnedValue(await UnitOfWork.PrdSelectedGroup.SaveRangeAsync(list, tranName)); res.ThrowExceptionIfError(); if (autoTran) { //CommitTransAction } } catch (Exception ex) { if (autoTran) { //RollBackTransAction } WebErrorLog.ErrorInstence.StartErrorLog(ex); res.AddReturnedValue(ex); } return(res); }
public static async Task <ReturnedSaveFuncInfo> StartErteghaAsync() { var res = new ReturnedSaveFuncInfo(); try { var cn = new SqlConnection(Setting.AppSettings.DefaultConnectionString); res.AddReturnedValue(await DataBaseUtilities.RunScript.RunAsync(Properties.Resources.Ertegha, cn)); res.ThrowExceptionIfError(); } catch (Exception ex) { WebErrorLog.ErrorInstence.StartErrorLog(ex); res.AddReturnedValue(ex); } return(res); }
public async Task <ReturnedSaveFuncInfo> RemoveAsync(string tranName = "") { var res = new ReturnedSaveFuncInfo(); var autoTran = string.IsNullOrEmpty(tranName); if (autoTran) { tranName = Guid.NewGuid().ToString(); } try { if (autoTran) { //BeginTransaction } var allList = await PrdFeatureBussines.GetAllByFeaturesGuidAsync(Guid); if (allList.Count > 0) { res.AddReturnedValue(ReturnedState.Error, "از این ویژگی در تعریف کالا استفاده شده است"); return(res); } res.AddReturnedValue(await UnitOfWork.Feature.RemoveAsync(Guid, tranName)); res.ThrowExceptionIfError(); if (autoTran) { //CommitTransAction } } catch (Exception ex) { if (autoTran) { //RollBackTransAction } WebErrorLog.ErrorInstence.StartErrorLog(ex); res.AddReturnedValue(ex); } return(res); }
public static async Task InsertDefaultDataAsync() { var dbContext = new ModelContext(); var res = new ReturnedSaveFuncInfo(); #region Users var allusers = await UsersBussines.GetAllAsync(); if (allusers == null || allusers.Count <= 0) { var user = new UsersBussines() { Guid = Guid.NewGuid(), Name = "مجید خاکپور", UserName = "******", Email = "*****@*****.**", IsBlock = false, Mobile = "9382420272", Modified = DateTime.Now, Status = true, Type = EnUserType.Manager }; var ue = new UTF8Encoding(); var bytes = ue.GetBytes("9382420272"); var md5 = new MD5CryptoServiceProvider(); var hashBytes = md5.ComputeHash(bytes); user.Password = System.Text.RegularExpressions.Regex.Replace(BitConverter.ToString(hashBytes), "-", "") .ToLower(); res.AddReturnedValue(await user.SaveAsync()); res.ThrowExceptionIfError(); } #endregion await dbContext.SaveChangesAsync(); dbContext.Dispose(); }