Esempio n. 1
0
 private void SetRoles(string currentRole = "")
 {
     using (var db = new SmDbContext())
     {
         var roles = db.AspNetRoles.ToList();
         if (roles.Count() == 0)
         {
             roles.Add(new AspNetRoles {
                 Id = Guid.NewGuid().ToString(), Name = "Администратор"
             });
             roles.Add(new AspNetRoles {
                 Id = Guid.NewGuid().ToString(), Name = "Директор"
             });
             roles.Add(new AspNetRoles {
                 Id = Guid.NewGuid().ToString(), Name = "Менеджер"
             });
             roles.Add(new AspNetRoles {
                 Id = Guid.NewGuid().ToString(), Name = "Продавец"
             });
             roles.Add(new AspNetRoles {
                 Id = Guid.NewGuid().ToString(), Name = "Кассир"
             });
             db.AspNetRoles.AddRange(roles);
             db.SaveChanges();
         }
         ViewBag.Roles = roles.OrderBy(x => x.Name).Select(x => new SelectListItem {
             Value = x.Id, Text = x.Name, Selected = x.Id == currentRole
         }).ToList();
     }
 }
Esempio n. 2
0
        public ActionResult Details(int id)
        {
            using (var db = new SmDbContext())
            {
                var entity = db.Incomes.First(x => x.Id == id);
                var model  = new IncomeViewModel
                {
                    DocumentNumber = entity.DocumentNumber,
                    Id             = entity.Id,
                    IncomeDate     = entity.IncomeDate,
                    Operator       = entity.Operator.Lastname + " " + entity.Operator.Firstname,
                    SupplierId     = entity.SupplierId,
                    Supplier       = entity.Supplier.Name,
                    Processed      = entity.Processed
                };

                model.IncomeItems = db.IncomeItems.Where(x => x.IncomeId == id).Select(x => new IncomeItemViewModel
                {
                    Id               = x.Id,
                    Amount           = x.Amount,
                    Price            = x.Price,
                    GoodsId          = x.GoodsId,
                    GoodsBrand       = x.Goods.Brand,
                    GoodsCategory    = x.Goods.GoodsCategory.Name,
                    GoodsName        = x.Goods.Name,
                    GoodsSubCategory = x.Goods.GoodsSubCategory == null ? "" : x.Goods.GoodsSubCategory.Name,
                }).ToArray();
                return(View(model));
            }
        }
Esempio n. 3
0
        // GET: Income
        public ActionResult Index(int page = 0, string search = "")
        {
            ViewBag.searchValue = search;
            ViewBag.page        = page;
            using (var db = new SmDbContext())
            {
                var list = db.Incomes.Select(x => new IncomeViewModel
                {
                    DocumentNumber = x.DocumentNumber,
                    Id             = x.Id,
                    IncomeDate     = x.IncomeDate,
                    Operator       = x.Operator.Lastname + " " + x.Operator.Firstname,
                    Supplier       = x.Supplier.Name,
                    Processed      = x.Processed
                });

                if (!string.IsNullOrEmpty(search))
                {
                    list = list.Where(x => x.DocumentNumber.Contains(search) || x.Operator.Contains(search) || x.Supplier.Contains(search));
                }

                list = list.OrderByDescending(x => x.IncomeDate).Skip(page * 50).Take(50);

                return(View(list.ToArray()));
            }
        }
Esempio n. 4
0
 public ActionResult Edit(SupplierViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         using (var db = new SmDbContext())
         {
             var entity = db.Suppliers.FirstOrDefault(x => x.Id == model.Id);
             if (entity == null)
             {
                 entity = new Supplier();
                 db.Suppliers.Add(entity);
             }
             entity.Name        = model.Name;
             entity.Identifier  = model.Identifier;
             entity.Address     = model.Address;
             entity.Description = model.Description;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("Name", ex);
         return(View(model));
     }
 }
Esempio n. 5
0
 public SmRoleProvider()
 {
     this._dbContext       = new SmDbContext();
     this._userService     = new SmUserService <SmUser>(this._dbContext);
     this._roleService     = new SmRoleService <SmRole>(this._dbContext);
     this._userRoleService = new SmUserRoleService <SmUserRole>(this._dbContext);
 }
Esempio n. 6
0
        private static async Task LoadPluginFile(SmDbContext db, ScheduleEntity model)
        {
            var master = db.ServerNodes.FirstOrDefault(x => x.NodeType == "master");

            if (master == null)
            {
                throw new InvalidOperationException("master not found.");
            }
            var sourcePath = $"{master.AccessProtocol}://{master.Host}/static/downloadpluginfile?pluginname={model.AssemblyName}";
            var zipPath    = $"{ConfigurationCache.PluginPathPrefix}\\{model.AssemblyName}.zip".ToPhysicalPath();
            var pluginPath = $"{ConfigurationCache.PluginPathPrefix}\\{model.Id}".ToPhysicalPath();

            using (WebClient client = new WebClient())
            {
                try
                {
                    await client.DownloadFileTaskAsync(new Uri(sourcePath), zipPath);
                }
                catch (Exception ex)
                {
                    LogHelper.Warn($"下载程序包异常,地址:{sourcePath}", model.Id);
                    throw ex;
                }
            }
            //将指定 zip 存档中的所有文件都解压缩到各自对应的目录下
            ZipFile.ExtractToDirectory(zipPath, pluginPath, true);
            System.IO.File.Delete(zipPath);
        }
Esempio n. 7
0
        public ActionResult Edit(int id)
        {
            using (var db = new SmDbContext())
            {
                var entity = db.Goods.First(x => x.Id == id);
                var model  = new GoodsViewModel
                {
                    Id                 = entity.Id,
                    Brand              = entity.Brand,
                    Description        = entity.Description,
                    GoodsCategoryId    = entity.GoodsCategoryId,
                    GoodsSubCategoryId = entity.GoodsSubCategoryId,
                    Name               = entity.Name,
                    Price              = entity.Price,
                    ProductCode        = entity.ProductCode,
                    Quantity           = entity.Quantity
                };

                var list = db.GoodsSubCategories.Where(x => x.GoodsCategoryId == entity.GoodsCategoryId).Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.Name,
                }).OrderBy(x => x.Text).ToList();

                ViewBag.GoodsSubCategories = list;

                return(View(model));
            }
        }
Esempio n. 8
0
        public ActionResult Details(int id)
        {
            using (var db = new SmDbContext())
            {
                var entity = db.Sales.First(x => x.Id == id);
                var model  = new SaleViewModel
                {
                    Paytype           = entity.Paytype,
                    Id                = entity.Id,
                    ClientIdentifier  = entity.Order.ClientIdentifier,
                    ClientName        = entity.Order.ClientName,
                    OrderId           = entity.OrderId,
                    RealisationDate   = entity.RealizationDate,
                    ClientAddress     = entity.Order.ClientAddress,
                    ClientDescription = entity.Order.ClientDescription,
                    Operator          = entity.Operator.Lastname + " " + entity.Operator.Firstname,
                    OrderDate         = entity.Order.OrderDate,
                };

                model.SaleItems = db.SaleItems.Where(x => x.SaleId == id).Select(x => new SaleItemViewModel
                {
                    Id               = x.Id,
                    Amount           = x.Amount,
                    Price            = x.Price,
                    GoodsId          = x.GoodsId,
                    GoodsBrand       = x.Goods.Brand,
                    GoodsCategory    = x.Goods.GoodsCategory.Name,
                    GoodsName        = x.Goods.Name,
                    GoodsSubCategory = x.Goods.GoodsSubCategory == null ? "" : x.Goods.GoodsSubCategory.Name,
                    Discount         = x.Discount,
                }).ToArray();
                return(View(model));
            }
        }
Esempio n. 9
0
        public ActionResult Delete(int id)
        {
            try
            {
                using (var db = new SmDbContext())
                {
                    var tr = db.Database.BeginTransaction();

                    var entity = db.Sales.First(x => x.Id == id);
                    foreach (var item in db.SaleItems.Where(x => x.SaleId == id))
                    {
                        db.SaleItems.Remove(item);
                    }
                    db.Sales.Remove(entity);
                    db.SaveChanges();
                    tr.Commit();
                }

                return(SuccessJson());
            }
            catch (Exception ex)
            {
                return(FailJson(ex));
            }
        }
Esempio n. 10
0
        // GET: Income
        public ActionResult Index(int page = 0, string search = "")
        {
            ViewBag.searchValue = search;
            ViewBag.page        = page;
            using (var db = new SmDbContext())
            {
                var list = db.Orders.Select(x => new OrderViewModel
                {
                    Id                = x.Id,
                    OrderDate         = x.OrderDate,
                    ClientAddress     = x.ClientAddress,
                    ClientName        = x.ClientName,
                    ClientDescription = x.ClientDescription,
                    ClientIdentifier  = x.ClientIdentifier,
                    Operator          = x.Operator.Lastname + " " + x.Operator.Firstname,
                    HasSale           = x.Sales.Any()
                });

                if (!string.IsNullOrEmpty(search))
                {
                    list = list.Where(x => x.Id.ToString().Contains(search) ||
                                      x.Operator.Contains(search) ||
                                      x.ClientIdentifier.Contains(search) ||
                                      x.ClientDescription.Contains(search) ||
                                      x.ClientName.Contains(search));
                }

                list = list.OrderByDescending(x => x.OrderDate).Skip(page * 50).Take(50);

                return(View(list.ToArray()));
            }
        }
Esempio n. 11
0
 public ActionResult Edit(GoodsSubCategoryViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         using (var db = new SmDbContext())
         {
             var entity = db.GoodsSubCategories.FirstOrDefault(x => x.Id == model.Id);
             if (entity == null)
             {
                 entity = new GoodsSubCategory();
                 db.GoodsSubCategories.Add(entity);
             }
             entity.Name            = model.Name;
             entity.Description     = model.Description;
             entity.GoodsCategoryId = model.GoodsCategoryId;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("Name", ex);
         return(View(model));
     }
 }
Esempio n. 12
0
        public ActionResult Edit(UserViewModel model)
        {
            if (string.IsNullOrEmpty(model.Id) && string.IsNullOrEmpty(model.Password))
            {
                ModelState.AddModelError("Password", "Требуется поле Пароль.");
            }

            if (!ModelState.IsValid)
            {
                SetRoles(model.Role);
                return(View(model));
            }
            try
            {
                using (var db = new SmDbContext())
                {
                    var user = db.AspNetUsers.FirstOrDefault(x => x.Id == model.Id);
                    if (user == null)
                    {
                        user = new AspNetUsers {
                            Id = Guid.NewGuid().ToString()
                        };
                        db.AspNetUsers.Add(user);
                        user.UserName      = model.UserName;
                        user.SecurityStamp = Guid.NewGuid().ToString();
                    }
                    user.Email       = model.Email;
                    user.Lastname    = model.Lastname;
                    user.Firstname   = model.Firstname;
                    user.PhoneNumber = model.PhoneNumber;
                    if (!string.IsNullOrEmpty(model.Password))
                    {
                        var ph = new Microsoft.AspNet.Identity.PasswordHasher();
                        user.PasswordHash = ph.HashPassword(model.Password);
                    }
                    if (!string.IsNullOrEmpty(model.Role))
                    {
                        var role = db.AspNetRoles.FirstOrDefault(x => x.Id == model.Role);
                        if (role != null)
                        {
                            user.AspNetRoles.Clear();
                            user.AspNetRoles.Add(role);
                        }
                    }
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("UserName", ex);

                SetRoles(model.Role);
                return(View(model));
            }
        }
Esempio n. 13
0
        private void initProductsLevel1(
            SmDbContext context, int parentId)
        {
            for (int i = 301; i < (i + 1); i++)
            {
                bool isSubItem = true;

                int    smMenuId  = i;
                String name      = String.Empty;
                String nameCn    = String.Empty;
                String nameUs    = String.Empty;
                int?   orderSn   = null;
                String url       = String.Empty;
                bool   isEnabled = true;

                switch (i)
                {
                case 301:
                    name    = "智慧簡訊機器人";
                    nameCn  = "智慧简讯机器人";
                    nameUs  = "Smart Sms Robot";
                    orderSn = 1;
                    url     = "https://play.google.com/store/apps/details?id=com.jb.Android.JBSMS_GP&hl=zh_HK";
                    break;

                default:
                    isSubItem = false;
                    break;
                }

                if (isSubItem)
                {
                    context.SmMenus.Add(new SmMenu()
                    {
                        SmMenuId  = smMenuId,
                        Name      = name,
                        NameCn    = nameCn,
                        NameUs    = nameUs,
                        OrderSn   = orderSn,
                        ParentId  = parentId,
                        Url       = url,
                        IsEnabled = isEnabled
                    });


                    adminMenuPermissions.Add(smMenuId);
                    normalUserMenuPermissions.Add(smMenuId);
                }
                else //Won't add the item and go for the next item.
                {
                    isSubItem = true;
                }
            }
        }
Esempio n. 14
0
 // GET: Income/Create
 public ActionResult Create()
 {
     using (var db = new SmDbContext())
     {
         ViewBag.Suppliers = db.Suppliers.Select(x => new SelectListItem
         {
             Value = x.Id.ToString(),
             Text  = x.Name
         }).ToList();
     }
     return(View("Edit"));
 }
Esempio n. 15
0
 private void initWahleeRoleMenus(
     SmDbContext context,
     int roleId, List <int> menuIds)
 {
     foreach (int menuId in menuIds)
     {
         context.SmRoleMenus.Add(new SmRoleMenu()
         {
             SmMenuId = menuId,
             SmRoleId = roleId
         });
     }
 }
Esempio n. 16
0
        public GoodsController()
        {
            using (var db = new SmDbContext())
            {
                var list = db.GoodsCategories.Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.Name,
                }).OrderBy(x => x.Text).ToList();

                ViewBag.GoodsCategories = list;
            }
        }
Esempio n. 17
0
 public ActionResult ListJson()
 {
     using (var db = new SmDbContext())
     {
         var list = db.GoodsCategories.Select(x => new
         {
             id   = x.Id,
             text = x.Name,
             x.Description
         }).OrderBy(x => x.text).ToArray();
         return(Json(new { results = list, pagination = new { more = false } }, JsonRequestBehavior.AllowGet));
     }
 }
        public static void AddScheduleMasterDb(this IServiceCollection services, IConfiguration configuration)
        {
            ConfigurationCache.DbConnector = new DbConnector
            {
                Provider         = (DbProvider)Enum.Parse(typeof(DbProvider), configuration["DbConnector:Provider"] ?? "mysql", true),
                ConnectionString = configuration["DbConnector:ConnectionString"]
            };

            services.AddDbContext <SmDbContext>();
            using (var ctx = new SmDbContext())
            {
                ctx.Database.EnsureCreated();
            }
        }
Esempio n. 19
0
        public ActionResult Index()
        {
            using (var db = new SmDbContext())
            {
                var list = db.GoodsCategories.Select(x => new GoodsCategoryViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description
                }).OrderBy(x => x.Name).ToArray();

                return(View(list));
            };
        }
Esempio n. 20
0
        public ActionResult Edit(int Id)
        {
            using (var db = new SmDbContext())
            {
                var model = db.GoodsCategories.Select(x => new GoodsCategoryViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description
                }).First(x => x.Id == Id);

                return(View(model));
            };
        }
Esempio n. 21
0
 private void InitSmRoles(SmDbContext context)
 {
     context.SmRoles.Add(new SmRole()
     {
         Name        = "Admin",
         Description = "系統管理者",
         IsEnabled   = true
     });
     context.SmRoles.Add(new SmRole()
     {
         Name        = "User",
         Description = "一般使用者",
         IsEnabled   = true
     });
 }
Esempio n. 22
0
        public ActionResult Employees()
        {
            using (var db = new SmDbContext())
            {
                var list = db.AspNetUsers.Select(x => new SelectListItem {
                    Value = x.Id, Text = x.Lastname + " " + x.Firstname
                }).OrderBy(x => x.Text).ToList();
                list.Insert(0, new SelectListItem {
                    Value = string.Empty, Text = "Все"
                });
                ViewBag.Employees = list;
            }

            return(View("EmployeesRequest"));
        }
Esempio n. 23
0
        public ActionResult ListJson(int categoryId)
        {
            using (var db = new SmDbContext())
            {
                var list = db.GoodsSubCategories
                           .Where(x => x.GoodsCategoryId == categoryId)
                           .Select(x => new
                {
                    id   = x.Id,
                    text = x.Name,
                });

                return(Json(list.OrderBy(x => x.text).ToArray(), JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 24
0
        public ActionResult Edit(int Id)
        {
            using (var db = new SmDbContext())
            {
                var model = db.Suppliers.Select(x => new SupplierViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Address     = x.Address,
                    Identifier  = x.Identifier,
                    Description = x.Description
                }).First(x => x.Id == Id);

                return(View(model));
            };
        }
Esempio n. 25
0
        public ActionResult Index()
        {
            using (var db = new SmDbContext())
            {
                var list = db.Suppliers.Select(x => new SupplierViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Address     = x.Address,
                    Identifier  = x.Identifier,
                    Description = x.Description
                }).OrderBy(x => x.Name).ToArray();

                return(View(list));
            };
        }
Esempio n. 26
0
        // GET: Users
        public ActionResult Index()
        {
            using (var db = new SmDbContext())
            {
                var users = db.AspNetUsers.Select(x => new UserViewModel
                {
                    Id          = x.Id,
                    Email       = x.Email,
                    Firstname   = x.Firstname,
                    Lastname    = x.Lastname,
                    UserName    = x.UserName,
                    PhoneNumber = x.PhoneNumber,
                    Role        = x.AspNetRoles.Select(r => r.Name).FirstOrDefault()
                }).ToList();

                return(View(users));
            }
        }
        public static void AddScheduleMasterDb(this IServiceCollection services)
        {
            var service       = services.First(x => x.ServiceType == typeof(IConfiguration));
            var configuration = (IConfiguration)service.ImplementationInstance;

            if (service.ImplementationInstance == null)
            {
                configuration = (IConfiguration)service.ImplementationFactory(null);
            }
            ConfigurationHelper.Config = configuration;

            services.AddScoped <ISqlContext, SmDbContext>();
            services.AddScoped <SmDbContext>();
            using (var ctx = new SmDbContext())
            {
                ctx.InitTables();
            }
        }
Esempio n. 28
0
        public async Task Execute(IJobExecutionContext context)
        {
            _sid = Guid.Parse(context.JobDetail.Key.Name);

            using (var scope = new ScopeDbContext())
            {
                _db = scope.GetDbContext();
                var locker = scope.GetService <HosLock.IHosLock>();
                if (locker.TryGetLock(context.JobDetail.Key.Name))
                {
                    await InnerRun(context);
                }
                else
                {
                    throw new JobExecutionException("lock_failed");
                }
            }
        }
Esempio n. 29
0
        public ActionResult Delete(int Id)
        {
            try
            {
                using (var db = new SmDbContext())
                {
                    var entity = db.Suppliers.First(x => x.Id == Id);
                    db.Suppliers.Remove(entity);
                    db.SaveChanges();

                    return(SuccessJson());
                }
            }
            catch (Exception ex)
            {
                return(FailJson(ex));
            }
        }
Esempio n. 30
0
        public ActionResult Delete(string Id)
        {
            try
            {
                using (var db = new SmDbContext())
                {
                    var user = db.AspNetUsers.First(x => x.Id == Id);
                    db.AspNetUsers.Remove(user);
                    db.SaveChanges();

                    return(SuccessJson());
                }
            }
            catch (Exception ex)
            {
                return(FailJson(ex));
            }
        }