コード例 #1
0
        public bool Add(EF.KPI entity)
        {
            try
            {
                for (int i = 1; i < 10000; i++)
                {
                    string code = i.ToString("D4");
                    if (_dbContext.KPIs.FirstOrDefault(x => x.Code == code) == null)
                    {
                        entity.Code = code;
                        break;
                    }
                }
                _dbContext.KPIs.Add(entity);
                _dbContext.SaveChanges();

                List <EF.KPILevel> kpiLevelList = new List <EF.KPILevel>();
                var levels = _dbContext.Levels.ToList();
                foreach (var level in levels)
                {
                    var kpilevel = new EF.KPILevel();
                    kpilevel.LevelID = level.ID;
                    kpilevel.KPIID   = entity.ID;
                    kpiLevelList.Add(kpilevel);
                }
                _dbContext.KPILevels.AddRange(kpiLevelList);
                _dbContext.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: LevelDAO.cs プロジェクト: SyPham/KPI-MVC5-Ajax
        public async Task <bool> Add(Level level)
        {
            List <EF.KPILevel> kpiLevelList = new List <EF.KPILevel>();

            if (level.LevelNumber == 0)
            {
                return(false);
            }
            try
            {
                level.Code = await CheckLevelNumberAndGenarateCode(level.LevelNumber ?? 0);

                _dbContext.Levels.Add(level);
                await _dbContext.SaveChangesAsync();

                var kpiVM = await _dbContext.KPIs.ToListAsync();

                kpiVM.ForEach(x =>
                {
                    var kpilevel     = new EF.KPILevel();
                    kpilevel.LevelID = level.ID;
                    kpilevel.KPIID   = x.ID;
                    kpiLevelList.Add(kpilevel);
                });
                _dbContext.KPILevels.AddRange(kpiLevelList);
                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #3
0
 public bool AddKPILevel(EF.KPILevel entity)
 {
     _dbContext.KPILevels.Add(entity);
     try
     {
         _dbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #4
0
ファイル: KPIAdminDAO.cs プロジェクト: SyPham/KPI-MVC5-Ajax
        public async Task <bool> AddKPILevel(EF.KPILevel entity)
        {
            _dbContext.KPILevels.Add(entity);
            try
            {
                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #5
0
ファイル: FactoryAdminDAO.cs プロジェクト: phuhoang09/KPI
        public int Add(EF.Factory entity)
        {
            var code = entity.Code.ToUpper();
            List <EF.KPILevel> kpiLevelList = new List <EF.KPILevel>();

            if (_dbContext.Factorys.FirstOrDefault(x => x.Code == code) != null)
            {
                return(2);
            }
            if (_dbContext.KPILevels.FirstOrDefault(x => x.KPICode == entity.Code) != null)
            {
                return(2);
            }
            //get all kpi
            var kpis = new KPIAdminDAO().GetAll();

            foreach (var kpi in kpis)
            {
                var kpilevel = new EF.KPILevel();
                kpilevel.TableID = code;
                kpilevel.KPICode = kpi.Code;
                kpilevel.Name    = kpi.Name;
                kpilevel.Checked = false;
                kpiLevelList.Add(kpilevel);
            }
            try
            {
                entity.Code = entity.Code.ToUpper();
                _dbContext.Factorys.Add(entity);
                _dbContext.KPILevels.AddRange(kpiLevelList);
                _dbContext.SaveChanges();
                return(1);
            }
            catch
            {
                return(0);
            }
        }
コード例 #6
0
        public int Add(EF.User entity)
        {
            entity.Code = entity.Code.ToSafetyString().ToUpper();
            List <EF.KPILevel> kpiLevelList = new List <EF.KPILevel>();

            try
            {
                entity.Password = entity.Password.SHA256Hash();
                entity.State    = true;
                entity.IsActive = true;
                _dbContext.Users.Add(entity);

                _dbContext.SaveChanges();

                IEnumerable <KPIViewModel> kpiVM = from kpi in _dbContext.KPIs
                                                   join cat in _dbContext.Categories on kpi.CategoryID equals cat.ID
                                                   select new KPIViewModel
                {
                    KPIID = kpi.ID,
                };
                foreach (var kpi in kpiVM)
                {
                    var kpilevel = new EF.KPILevel();
                    kpilevel.LevelID = entity.ID;
                    kpilevel.KPIID   = kpi.KPIID;
                    kpiLevelList.Add(kpilevel);
                }

                _dbContext.KPILevels.AddRange(kpiLevelList);
                _dbContext.SaveChanges();

                return(1);
            }
            catch
            {
                return(0);
            }
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>Update các cột WeeklyChecked, MonthlyChecked, QuaterlyChecked, YearlyChecked</returns>
        public bool Update(EF.KPILevel entity)
        {
            var comparedt = new DateTime(2001, 1, 1);
            var kpiLevel  = _dbContext.KPILevels.FirstOrDefault(x => x.KPIID == entity.KPIID && x.LevelID == entity.LevelID);

            if (entity.Weekly != null)
            {
                kpiLevel.Weekly = entity.Weekly;
            }
            if (DateTime.Compare(entity.Monthly.Value, comparedt) != 0)
            {
                kpiLevel.Monthly = entity.Monthly;
            }
            if (DateTime.Compare(entity.Quaterly.Value, comparedt) != 0)
            {
                kpiLevel.Quaterly = entity.Quaterly;
            }
            if (DateTime.Compare(entity.Yearly.Value, comparedt) != 0)
            {
                kpiLevel.Yearly = entity.Yearly;
            }
            if (entity.WeeklyChecked != null)
            {
                kpiLevel.WeeklyChecked = entity.WeeklyChecked;
            }
            if (entity.MonthlyChecked != null)
            {
                kpiLevel.MonthlyChecked = entity.MonthlyChecked;
            }
            if (entity.QuaterlyChecked != null)
            {
                kpiLevel.QuaterlyChecked = entity.QuaterlyChecked;
            }
            if (entity.MonthlyChecked != null)
            {
                kpiLevel.MonthlyChecked = entity.MonthlyChecked;
            }
            if (entity.YearlyChecked != null)
            {
                kpiLevel.YearlyChecked = entity.YearlyChecked;
            }
            if (entity.WeeklyPublic != null)
            {
                kpiLevel.WeeklyPublic = entity.WeeklyPublic;
            }
            if (entity.MonthlyPublic != null)
            {
                kpiLevel.MonthlyPublic = entity.MonthlyPublic;
            }
            if (entity.QuaterlyPublic != null)
            {
                kpiLevel.QuaterlyPublic = entity.QuaterlyPublic;
            }
            if (entity.YearlyPublic != null)
            {
                kpiLevel.YearlyPublic = entity.YearlyPublic;
            }
            if (entity.Checked != null)
            {
                kpiLevel.Checked      = entity.Checked;
                kpiLevel.KPILevelCode = entity.KPILevelCode;
            }

            kpiLevel.UserCheck = entity.UserCheck;
            kpiLevel.TimeCheck = entity.TimeCheck;
            //kpiLevel.Code = entity.Code;

            try
            {
                _dbContext.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                //logging
                return(false);
            }
        }
コード例 #8
0
ファイル: LevelDAO.cs プロジェクト: SyPham/KPI-MVC5-Ajax
        public async Task <bool> AddOrUpdate(Level entity)
        {
            entity.Code = entity.Code.ToUpper();
            List <EF.KPILevel> kpiLevelList = new List <KPILevel>();

            if (entity.ID == 0)
            {
                if (await _dbContext.Levels.FirstOrDefaultAsync(x => x.Code == entity.Code) != null)
                {
                    return(false);
                }
                try
                {
                    var level = new Level()
                    {
                        Name        = entity.Name,
                        Code        = entity.Code,
                        LevelNumber = entity.LevelNumber,
                        ParentCode  = entity.ParentCode,
                        ParentID    = entity.ParentID
                    };
                    _dbContext.Levels.Add(level);

                    await _dbContext.SaveChangesAsync();

                    var kpiVM = await _dbContext.KPIs.ToListAsync();

                    kpiVM.ForEach(x =>
                    {
                        var kpilevel     = new EF.KPILevel();
                        kpilevel.LevelID = level.ID;
                        kpilevel.KPIID   = x.ID;
                        kpiLevelList.Add(kpilevel);
                    });
                    //foreach (var kpi in kpiVM)
                    //{
                    //    var kpilevel = new EF.KPILevel();
                    //    kpilevel.LevelID = level.ID;
                    //    kpilevel.KPIID = kpi.KPIID;
                    //    kpiLevelList.Add(kpilevel);
                    //}
                    _dbContext.KPILevels.AddRange(kpiLevelList);
                    await _dbContext.SaveChangesAsync();

                    return(true);
                }
                catch (Exception ex)
                {
                    var message = ex.Message;
                    return(false);
                }
            }
            else
            {
                try
                {
                    var item = await _dbContext.Levels.FirstOrDefaultAsync(x => x.ID == entity.ID);

                    item.Code        = entity.Code;
                    item.Name        = entity.Name;
                    item.LevelNumber = entity.LevelNumber;
                    item.ParentID    = entity.ParentID;
                    await _dbContext.SaveChangesAsync();

                    return(true);
                }
                catch (Exception ex)
                {
                    var message = ex.Message;
                    return(false);
                }
            }
        }
コード例 #9
0
ファイル: LevelDAO.cs プロジェクト: SyPham/KPISystem
        public bool AddOrUpdate(EF.Level entity)
        {
            entity.Code = entity.Code.ToUpper();
            List <EF.KPILevel> kpiLevelList = new List <EF.KPILevel>();

            if (entity.ID == 0)
            {
                if (_dbContext.Levels.FirstOrDefault(x => x.Code == entity.Code) != null)
                {
                    return(false);
                }
                try
                {
                    var level = new EF.Level()
                    {
                        Name        = entity.Name,
                        Code        = entity.Code,
                        LevelNumber = entity.LevelNumber,
                        ParentCode  = entity.ParentCode,
                        ParentID    = entity.ParentID
                    };
                    _dbContext.Levels.Add(level);
                    _dbContext.SaveChanges();

                    IEnumerable <KPIViewModel> kpiVM = from kpi in _dbContext.KPIs
                                                       join cat in _dbContext.Categories on kpi.CategoryID equals cat.ID
                                                       select new KPIViewModel
                    {
                        KPIID = kpi.ID,
                    };
                    foreach (var kpi in kpiVM)
                    {
                        var kpilevel = new EF.KPILevel();
                        kpilevel.LevelID = level.ID;
                        kpilevel.KPIID   = kpi.KPIID;
                        kpiLevelList.Add(kpilevel);
                    }
                    try
                    {
                        _dbContext.KPILevels.AddRange(kpiLevelList);
                        _dbContext.SaveChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        var message = ex.Message;
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    var message = ex.Message;
                    return(false);
                }
            }
            else
            {
                try
                {
                    var item = _dbContext.Levels.FirstOrDefault(x => x.ID == entity.ID);
                    item.Code        = entity.Code;
                    item.Name        = entity.Name;
                    item.LevelNumber = entity.LevelNumber;
                    item.ParentID    = entity.ParentID;
                    _dbContext.SaveChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    var message = ex.Message;
                    return(false);
                }
            }
        }