Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        private async void btnFinish_Click(object sender, EventArgs e)
        {
            try
            {
                if (cls.Guid == Guid.Empty)
                {
                    cls.Guid = Guid.NewGuid();
                }

                if (string.IsNullOrEmpty(txtName.Text))
                {
                    frmNotification.PublicInfo.ShowMessage("عنوان گروه نمی تواند خالی باشد");
                    txtName.Focus();
                    return;
                }
                if (!await CustomerGroupBussines.CheckName(cls.Guid, txtName.Text.Trim()))
                {
                    frmNotification.PublicInfo.ShowMessage("عنوان وارد شده تکراری است");
                    txtName.Focus();
                    return;
                }

                cls.Name        = txtName.Text.Trim();
                cls.Description = txtDesc.Text;
                cls.ParentGuid  = (Guid)cmbParent.SelectedValue;
                var res = await cls.SaveAsync();

                if (res.HasError)
                {
                    frmNotification.PublicInfo.ShowMessage(res.ErrorMessage);
                    return;
                }
                DialogResult = DialogResult.OK;
                frmLoading.PublicInfo.ShowForm();
                Close();
            }
            catch (Exception exception)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(exception);
            }
        }