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); } }
public bool Add(EF.Favourite entity) { try { _dbContext.Favourites.Add(entity); _dbContext.SaveChanges(); return(true); } catch (Exception ex) { var message = ex.Message; return(false); } }
public async Task <object> Update(int ID) { var some = _dbContext.NotificationDetails.FirstOrDefault(x => x.ID == ID); var user = _dbContext.Users; var kpilevel = _dbContext.KPILevels; try { some.Seen = true; _dbContext.SaveChanges(); //var detail = _dbContext.Notifications.FirstOrDefault(x => x.ID == some.NotificationID); var detail = await _dbContext.Notifications.FirstOrDefaultAsync(x => x.ID == some.NotificationID); var tag = await _dbContext.Tags.Where(x => x.CommentID == detail.CommentID).Select(x => x.UserID).ToListAsync(); var listArr = string.Empty; if (tag.Count > 0) { listArr = string.Join(",", user.Where(x => tag.Contains(x.ID)).Select(x => x.FullName).ToArray());; } var vm = new NotificationViewModel(); vm.ID = detail.ID; vm.Title = detail.Title; vm.CreateTime = detail.CreateTime; vm.Link = detail.Link; vm.Tag = listArr; vm.Content = detail.Content; vm.Sender = user.Find(detail.UserID).FullName; vm.Recipient = listArr; vm.Content = detail.Content; vm.Title = detail.Title; vm.KPIName = detail.KPIName; vm.Owner = kpilevel.FirstOrDefault(a => a.KPILevelCode == detail.KPILevelCode).Owner; vm.Manager = kpilevel.FirstOrDefault(a => a.KPILevelCode == detail.KPILevelCode).OwnerManagerment; //vm.PIC = kpilevel.FirstOrDefault(a => a.KPILevelCode == detail.KPILevelCode).PIC; vm.PIC = detail.UserID; if (detail.ActionplanID > 0) { vm.DueDate = _dbContext.ActionPlans.FirstOrDefault(x => x.ID == detail.ActionplanID).Deadline.ToString("MM/dd/yyyy"); } return(new { status = true, data = vm }); } catch (Exception) { return(new { status = false, data = "" });; } }
public bool Add(EF.Category entity) { entity.Code = entity.Code.ToUpper(); try { _dbContext.Categories.Add(entity); _dbContext.SaveChanges(); return(true); } catch (Exception ex) { var message = ex.Message; return(false); } }
public long Add(ErrorMessage error) { var item = new ErrorMessage(); _dbContext.ErrorMessages.Add(error); _dbContext.SaveChanges(); return(error.ID); }
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); } }
public bool UpdateRemark(int dataid, string remark) { var model = _dbContext.Datas.FirstOrDefault(x => x.ID == dataid); try { model.Remark = remark.ToSafetyString(); _dbContext.SaveChanges(); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Thêm Category KPILevel /// </summary> /// <param name="entity"></param> /// <returns></returns> public async Task <bool> Add(CategoryKPILevel entity) { var item = await _dbContext.CategoryKPILevels.FirstOrDefaultAsync(x => x.KPILevelID == entity.KPILevelID && x.CategoryID == entity.CategoryID); if (item == null) { entity.Status = true; _dbContext.CategoryKPILevels.Add(entity); } else { item.Status = !item.Status; } try { _dbContext.SaveChanges(); return(true); } catch { return(false); } }
public bool UpdateRange(string listID) { if (listID == null) { return(false); } if (listID.Length > 0) { var arr = listID.Split(',').Select(Int32.Parse).ToList(); var some = _dbContext.NotificationDetails.Where(x => arr.Contains(x.ID)).ToList(); some.ForEach(a => a.Seen = true); try { _dbContext.SaveChanges(); return(true); } catch (Exception) { return(false); } } return(false); }
public async Task <bool> LockUser(int id) { var item = await _dbContext.Users.FirstOrDefaultAsync(x => x.ID == id); item.IsActive = !item.IsActive; try { _dbContext.SaveChanges(); return(true); } catch (Exception ex) { var message = ex.Message; //logging return(false); } }
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); } }
public bool Update(int key, string title, string code) { var item = _dbContext.Levels.FirstOrDefault(x => x.ID == key); if (item == null) { return(false); } else { item.Code = code; item.Name = title; try { _dbContext.SaveChanges(); return(true); } catch (Exception) { return(false); } } }
public int Commit() { try { var returnValue = dbcontext.SaveChanges(); if (dbTransaction != null) { dbTransaction.Commit(); } return(returnValue); } catch (Exception) { if (dbTransaction != null) { this.dbTransaction.Rollback(); } throw; } finally { this.Dispose(); } }
public AddCommentVM Add(ActionPlan entity, string subject) { var user = _dbContext.Users; var itemActionPlanDetail = new ActionPlanDetail(); var listEmail = new List <string[]>(); var listUserID = new List <int>(); var listFullNameTag = new List <string>(); var listTags = new List <Tag>(); var itemTag = _dbContext.Tags; try { if (entity.Description.IndexOf(";") == -1) { entity.Description = entity.Description; } else { var des = string.Empty; entity.Description.Split(';').ToList().ForEach(line => { des += line + " "; }); entity.Description = des; } _dbContext.ActionPlans.Add(entity); _dbContext.SaveChanges(); if (!entity.Tag.IsNullOrEmpty()) { string[] arrayString = new string[5]; if (entity.Tag.IndexOf(",") == -1) { var userItem = user.FirstOrDefault(x => x.Username == entity.Tag); if (userItem != null) { var tag = new Tag(); tag.ActionPlanID = entity.ID; tag.UserID = (int?)userItem.ID ?? 0; _dbContext.Tags.Add(tag); _dbContext.SaveChanges(); arrayString[0] = user.FirstOrDefault(x => x.ID == entity.UserID).FullName; arrayString[1] = userItem.Email; arrayString[2] = entity.Link; arrayString[3] = entity.Title; arrayString[4] = entity.Description; listFullNameTag.Add(userItem.FullName); listEmail.Add(arrayString); } } else { var list = entity.Tag.Split(','); var listUsers = _dbContext.Users.Where(x => list.Contains(x.Username)).ToList(); foreach (var item in listUsers) { var tag = new Tag(); tag.ActionPlanID = entity.ID; tag.UserID = item.ID; listTags.Add(tag); arrayString[0] = user.FirstOrDefault(x => x.ID == entity.UserID).FullName; arrayString[1] = item.Email; arrayString[2] = entity.Link; arrayString[3] = entity.Title; arrayString[4] = entity.Description; listFullNameTag.Add(item.FullName); listEmail.Add(arrayString); } _dbContext.Tags.AddRange(listTags); _dbContext.SaveChanges(); } } //Add vao Notification var notify = new Notification(); notify.ActionplanID = entity.ID; notify.Content = entity.Description; notify.UserID = entity.UserID; notify.Title = entity.Title; notify.Link = entity.Link; notify.Tag = string.Join(",", listFullNameTag); notify.Title = subject; new NotificationDAO().Add(notify); return(new AddCommentVM { Status = true, ListEmails = listEmail }); } catch (Exception ex) { var message = ex.Message; return(new AddCommentVM { Status = true, ListEmails = listEmail }); } }
public int Insert(TEntity entity) { dbcontext.Entry <TEntity>(entity).State = EntityState.Added; return(dbcontext.SaveChanges()); }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <returns>Update các cột WeeklyChecked, MonthlyChecked, QuarterlyChecked, YearlyChecked</returns> public async Task <bool> Update(ViewModel.UpdateKPILevelVM entity) { var comparedt = new DateTime(2001, 1, 1); var kpiLevel = await _dbContext.KPILevels.FirstOrDefaultAsync(x => x.ID == entity.ID); var kpiModel = await _dbContext.KPIs.FirstOrDefaultAsync(x => x.ID == kpiLevel.KPIID); var ocModel = await _dbContext.Levels.FirstOrDefaultAsync(x => x.ID == kpiLevel.LevelID); if (entity.Weekly != null) { kpiLevel.Weekly = entity.Weekly; } if (!entity.Monthly.IsNullOrEmpty()) { kpiLevel.Monthly = Convert.ToDateTime(entity.Monthly); } if (!entity.Quarterly.IsNullOrEmpty()) { kpiLevel.Quarterly = Convert.ToDateTime(entity.Quarterly); } if (!entity.Yearly.IsNullOrEmpty()) { kpiLevel.Yearly = Convert.ToDateTime(entity.Yearly); } if (entity.WeeklyChecked != null) { kpiLevel.WeeklyChecked = entity.WeeklyChecked; } if (entity.MonthlyChecked != null) { kpiLevel.MonthlyChecked = entity.MonthlyChecked; } if (entity.QuarterlyChecked != null) { kpiLevel.QuarterlyChecked = entity.QuarterlyChecked; } 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.QuarterlyPublic != null) { kpiLevel.QuarterlyPublic = entity.QuarterlyPublic; } if (entity.YearlyPublic != null) { kpiLevel.YearlyPublic = entity.YearlyPublic; } if (entity.Checked != null) { kpiLevel.Checked = entity.Checked; kpiLevel.KPILevelCode = ocModel.LevelNumber + ocModel.Code + kpiModel.Code; } kpiLevel.UserCheck = entity.UserCheck; kpiLevel.TimeCheck = DateTime.Now; kpiLevel.CreateTime = DateTime.Now; try { _dbContext.SaveChanges(); return(true); } catch (Exception ex) { var message = ex.Message; //logging return(false); } }
/// <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); } }
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); } } }
public bool AddRange1(List <EF.Data> entity) { foreach (var item in entity) { var itemcode = _dbContext.Datas.FirstOrDefault(x => x.KPILevelCode == item.KPILevelCode); if (itemcode == null) { try { _dbContext.Datas.Add(item); _dbContext.SaveChanges(); } catch (Exception ex) { var message = ex.Message; return(false); } } else if (item.Week > 0 && itemcode.Week == item.Week) { itemcode.Week = item.Week; try { _dbContext.SaveChanges(); } catch (Exception ex) { var message = ex.Message; return(false); } } else if (item.Month > 0 && itemcode.Month == item.Month) { itemcode.Month = item.Month; try { _dbContext.SaveChanges(); } catch (Exception ex) { var message = ex.Message; return(false); } } else if (item.Quarter > 0 && itemcode.Quarter == item.Quarter) { itemcode.Quarter = item.Quarter; try { _dbContext.SaveChanges(); } catch (Exception ex) { var message = ex.Message; return(false); } } else if (item.Year > 0 && itemcode.Year == item.Year) { itemcode.Year = item.Year; try { _dbContext.SaveChanges(); } catch (Exception ex) { var message = ex.Message; return(false); } } } return(true); }