コード例 #1
0
        public static string Translate(this string clsName, string fieldName, string en = "", string vn = "")
        {
            AddNewWord();
            try
            {
                xNgonNgu item = db.xNgonNgu.FirstOrDefault(x => x.ClassName.Equals(clsName) && x.FieldName.ToLower().Equals(fieldName.ToLower()));
                item = item ?? new xNgonNgu()
                {
                    ClassName = clsName,
                    FieldName = fieldName.ToLower(),
                    EN        = dicWord[fieldName.ToLower()].EN,
                    VN        = dicWord[fieldName.ToLower()].VN,
                };

                item.EN = string.IsNullOrEmpty(en) ? item.EN : en;
                item.VN = string.IsNullOrEmpty(vn) ? item.VN : vn;

                if (item.KeyID == 0)
                {
                    db.Add(item);
                }

                db.SaveChanges();

                return(item.VN);
            }
            catch { return(string.Empty); }
        }
コード例 #2
0
 public bool Delete(int id)
 {
     try
     {
         T item = entity.Find(id);
         if (item == null)
         {
             return(false);
         }
         entity.Remove(item);
         db.SaveChanges();
         return(true);
     }
     catch { return(false); }
 }
コード例 #3
0
        public static void SeedData(this IApplicationBuilder app)
        {
            _app = app;
            _db  = _app.ApplicationServices.GetService <zModel>();
            app.allControlller();

            if (!_db.ePhanQuyen.Any(n => n.TenQuyen.Equals("Admin")))
            {
                var nQuyen = new ePhanQuyen()
                {
                    TenQuyen = "Admin"
                };
                _db.ePhanQuyen.Add(nQuyen);

                if (_db.ChangeTracker.HasChanges())
                {
                    _db.SaveChanges();
                }

                _db.xChucNang.ToList().ForEach(n => _db.eQuyen.Add(new eQuyen()
                {
                    ChucNangID  = n.KeyID,
                    PhanQuyenID = nQuyen.KeyID
                }));

                if (_db.ChangeTracker.HasChanges())
                {
                    _db.SaveChanges();
                }
            }

            if (!_db.eTaiKhoan.Any(n => n.AccCode.Equals("admin")))
            {
                _db.eTaiKhoan.Add(new eTaiKhoan()
                {
                    AccCode     = "admin",
                    Password    = "******".Encrypt(),
                    AccName     = "admin",
                    PhanQuyenID = 1
                });
            }

            if (_db.ChangeTracker.HasChanges())
            {
                _db.SaveChanges();
            }
        }
コード例 #4
0
        private static void allControlller(this IApplicationBuilder app)
        {
            var lstChucNang = _db.xChucNang.ToList();

            foreach (ControllerActionDescriptor item in
                     app.ApplicationServices.GetServices <IActionDescriptorCollectionProvider>()
                     .First().ActionDescriptors.Items)
            {
                if (!item.ControllerName.Equals("Test"))
                {
                    string methods = "GET";
                    string route   = item.AttributeRouteInfo.Template.Trim().ToLower();
                    if (!route.StartsWith("/"))
                    {
                        route = "/" + route;
                    }
                    if (item.ActionConstraints != null)
                    {
                        methods = "";
                        try
                        {
                            methods = string.Join("|",
                                                  (
                                                      (Microsoft.AspNetCore.Mvc.Internal.HttpMethodActionConstraint)
                                                      item.ActionConstraints
                                                      .FirstOrDefault(n => n is Microsoft.AspNetCore.Mvc.Internal.HttpMethodActionConstraint))
                                                  .HttpMethods
                                                  .Distinct()
                                                  ).Trim().ToUpper();
                        }
                        catch { methods = "GET"; }
                    }
                    var chucnang = new xChucNang()
                    {
                        ModuleName     = Utils.ModuleHelper.ModuleName,
                        Route          = route,
                        Methods        = methods,
                        ControllerName = item.ControllerName
                    };
                    if (!lstChucNang.Any(n => n.Route.Equals(chucnang.Route) && n.Methods.Equals(chucnang.Methods)))
                    {
                        _db.xChucNang.Add(chucnang);
                    }
                }
            }

            if (_db.ChangeTracker.HasChanges())
            {
                _db.SaveChanges();
            }
        }
コード例 #5
0
ファイル: UnitOfWork.cs プロジェクト: hieuht300894/WebAPI-v3
 public int SaveChanges()
 {
     return(context.SaveChanges());
 }