public async Task <bool> SendDiary(int id) { try { List <TblNotifications> notifications = new List <TblNotifications>(); string bp = _context.HttpContext.User.FindFirst("Ma_Bp").Value; string to = _context.HttpContext.User.FindFirst("Ma_To").Value; string user = _context.HttpContext.User.FindFirst(ClaimTypes.Name).Value; int display = int.Parse(_context.HttpContext.User.FindFirst("Display").Value); DateTime nowDate = DateTime.Now; List <string> userReceive = new List <string>(); TblDaily tbl = await _db.TblDaily.FindAsync(id); if (display < 3) { userReceive = await(from u in _db.AppUser join cv in _db.TblCv on u.MaCv equals cv.MaCv where u.MaTo == to && cv.Display == 3 select u.UserName).ToListAsync(); tbl.StatusAutho1 = true; } else if (display > 2) { userReceive = await(from u in _db.AppUser join cv in _db.TblCv on u.MaCv equals cv.MaCv where cv.Display > display && (display < 4?u.MaBp == bp:1 == 1) select u.UserName).ToListAsync(); tbl.StatusAutho2 = true; tbl.StatusAutho3 = true; } foreach (string item in userReceive) { notifications.Add(new TblNotifications { SendId = user, ReceiveId = item, Notification = "Nhật ký công việc", Url = "/Diaries/Evaluates/Index/" + id, Status = false, Date = nowDate }); } bool status = await _notificationRepository.SaveList(notifications); if (status) { await _hubContext.Clients.Users(userReceive).SendAsync("GetNotification"); } return(status); } catch { return(false); } }
public async Task <IActionResult> Get(int id = 0) { TblDaily tbl = new TblDaily(); tbl.Date = DateTime.Today; if (id > 0) { tbl = await _diaryRepository.GetByMa(id); } return(PartialView("_Dairy", tbl)); }
public async Task <bool> Update(TblDaily tbl) { try { _db.Entry(tbl).State = EntityState.Modified; await _db.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task <bool> Save(TblDaily tbl) { try { tbl.UserName = _context.HttpContext.User.Identity.Name.ToString(); _db.Entry(tbl).State = EntityState.Added; await _db.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task <bool> Delete(int ma) { try { TblDaily tbl = new TblDaily(); tbl.Id = ma; _db.Entry(tbl).State = EntityState.Deleted; await _db.SaveChangesAsync(); return(true); } catch { return(false); } }
public async Task <IActionResult> Save([FromBody] TblDaily tbl) { bool status = await(tbl.Id > 0 ? _diaryRepository.Update(tbl) : _diaryRepository.Save(tbl)); return(Ok(new { status = status })); }