public async Task <ActionResult> ChangeDevelopment(Development selec, long id) { var Email = User.Identity.Name; // Name of current Login var Name = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == Email).FirstName; // UserId of CurrentLogin var UserCurrentId = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == Email).Id; //id of Employee var EmployeeId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.UserId == UserCurrentId).Id; //attachmet of UserCurrentLogin var attachment = adamUnit.AttachmentRepository.FirstOrDefault(x => x.OwnerId == EmployeeId.ToString()).FileName; // Id of current Login var IdOfCur = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == Email).Id; var task = adamUnit.TaskRepository.SingleOrDefault(x => x.Id == id); task.Development = selec; await adamUnit.TaskRepository.UpdateAsync(task); //retrive UserId of role var UserId = adamUnit.RoleRepository.GetUserIdOfRole(); // retriv UserName of role var userName = adamUnit.AppUserRepository.SingleOrDefault(x => x.Id == UserId).UserName; var notify = new Notfication(); notify.ToUserId = UserId; notify.OwnerUserId = IdOfCur; notify.TableName = TableName.task; notify.TablePkId = id; notify.IsRead = false; notify.Context = "Change status"; await adamUnit.NotificationRepository.InserAsync(notify); var Url = "/Admin/task/Details?id=" + id; if (adamUnit.TokenFireBaseRepository.Exists(x => x.UserId == UserId)) { var tokens = adamUnit.TokenFireBaseRepository.GetAll(x => x.UserId == UserId).Select(x => x.token); foreach (var token in tokens) { NotificationController.SendPushNotification(token, notify.Context, Name, Url, attachment); } } return(Json("ok")); }
public async Task <IActionResult> SaveTask(List <IFormFile> files, TaskVM taskVM) { if (ModelState.IsValid) { if (!adamUnit.TaskRepository.Exists(x => x.Name == taskVM.Name && x.ProjectId == taskVM.ProjectId)) { // Current login User Information var CurrentUserEmial = User.Identity.Name; var CurrentUserId = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).Id; var CurrentName = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).FirstName; var tas = new task(); taskVM.Development = Development.init; tas = taskVM.ToEntity(); await adamUnit.TaskRepository.InserAsync(tas); string recordId = tas.Id.ToString(); string webRootPath = _hostingEnvironment.WebRootPath; var state = adamUnit.AttachmentRepository.OnPostUpload(files, recordId, AttachmentOwner.Tasks, AttachmentType.Photo, webRootPath); var UserId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.Id == taskVM.EmployeeId).UserId; var UserName = adamUnit.AppUserRepository.SingleOrDefault(x => x.Id == UserId).UserName; // Retrive UserId of Admin var UserIdOfAdmin = adamUnit.RoleRepository.GetUserIdOfRole(); var attachment = ""; if (CurrentUserId == UserIdOfAdmin) { attachment = adamUnit.AttachmentRepository.FirstOrDefault(x => x.OwnerId == CurrentUserId).FileName; } else { var employeeId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.UserId == CurrentUserId).Id; attachment = adamUnit.AttachmentRepository .FirstOrDefault(x => x.OwnerId == employeeId.ToString()).FileName; } var notify = new Notfication(); notify.OwnerUserId = CurrentUserId; notify.ToUserId = UserId; notify.TableName = TableName.task; notify.TablePkId = taskVM.Id; notify.Context = "AddYouToTask"; await adamUnit.NotificationRepository.InserAsync(notify); var Url = "/Admin/task/Details?Id=" + taskVM.Id; if (adamUnit.TokenFireBaseRepository.Exists(x => x.UserId == UserId)) { var tokens = adamUnit.TokenFireBaseRepository.GetAll(x => x.UserId == UserId).Select(x => x.token); foreach (var token in tokens) { NotificationController.SendPushNotification(token, notify.Context, CurrentName, Url, attachment); } } TempData["SuccessMessage"] = "Created Successfully"; return(RedirectToAction(nameof(Index))); } ViewBag.Name = "Name is Exist Already"; ViewBag.Project = adamUnit.ProjectRepository.GetAll().ToList(); ViewBag.Employee = adamUnit.EmployeeRepository.GetAllInclude().ToList(); return(PartialView("_PartialTask", taskVM)); } ViewBag.Project = adamUnit.ProjectRepository.GetAll().ToList(); ViewBag.Employee = adamUnit.EmployeeRepository.GetAllInclude().ToList(); return(PartialView("_PartialTask", taskVM)); }
public async Task <JsonResult> Comments(string data, long recordId) { var CurrentUserEmial = User.Identity.Name; var FirstName = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).FirstName; var LastName = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).LastName; var CurrentUserId = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).Id; if (User.IsInRole(AppHelper.SuperAdminEndUser)) { var Attacment = adamUnit.AttachmentRepository.SingleOrDefault(x => x.OwnerId == CurrentUserId).FileName; var comment = new Comment(); comment.TableId = recordId; comment.TableName = TableName.Project; comment.context = data; comment.UserId = CurrentUserId; await adamUnit.CommentRepository.InserAsync(comment); // Ids of employee Joined to Project and send Notify to them by Admin var employeeIds = adamUnit.ProjectUserRepository.GetAll(x => x.ProjectId == recordId).Select(x => x.UserId) .ToList(); foreach (var empId in employeeIds) { var notify = new Notfication(); notify.OwnerUserId = CurrentUserId; notify.ToUserId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.Id == empId).UserId; notify.TableName = TableName.Project; notify.TablePkId = recordId; notify.Context = "AddComment"; await adamUnit.NotificationRepository.InserAsync(notify); var url = "/Admin/Project/Details?id=" + recordId; if (adamUnit.TokenFireBaseRepository.Exists(x => x.UserId == notify.ToUserId)) { var tokens = adamUnit.TokenFireBaseRepository.GetAll(x => x.UserId == notify.ToUserId).Select(x => x.token); foreach (var token in tokens) { NotificationController.SendPushNotification(token, notify.Context, FirstName, url, Attacment); } } } var idDb = comment.Id; return(Json(new { id = comment.Id, firstName = FirstName, lastName = LastName, attacment = Attacment, date = DateTime.Now.ToShortTimeString() })); } else { var employeeId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.UserId == CurrentUserId).Id; var Attacment = adamUnit.AttachmentRepository.SingleOrDefault(x => x.OwnerId == employeeId.ToString()).FileName; var comment = new Comment(); comment.TableId = recordId; comment.TableName = TableName.Project; comment.context = data; comment.UserId = CurrentUserId; await adamUnit.CommentRepository.InserAsync(comment); // Ids of employee Joined to Project and send Notify to them by Employee var employeeIds = adamUnit.ProjectUserRepository.GetAll(x => x.ProjectId == recordId && x.UserId != employeeId).Select(x => x.UserId) .ToList(); if (employeeIds.Count > 1) { foreach (var empId in employeeIds) { var UserId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.Id == empId && x.UserId != CurrentUserId).UserId; if (UserId != null) { var notify = new Notfication(); notify.OwnerUserId = CurrentUserId; notify.ToUserId = UserId; notify.TableName = TableName.Project; notify.TablePkId = recordId; notify.Context = "AddComment"; await adamUnit.NotificationRepository.InserAsync(notify); var url = "/Admin/Project/Details?id=" + recordId; if (adamUnit.TokenFireBaseRepository.Exists(x => x.UserId == UserId)) { var tokens = adamUnit.TokenFireBaseRepository.GetAll(x => x.UserId == UserId).Select(x => x.token); foreach (var token in tokens) { NotificationController.SendPushNotification(token, notify.Context, FirstName, url, Attacment); } } } } } // save and send Notification to Admin By Employee // UserId of Admin var UserIdOfAdmin = adamUnit.RoleRepository.GetUserIdOfRole(); var notfy = new Notfication(); notfy.OwnerUserId = CurrentUserId; notfy.ToUserId = UserIdOfAdmin; notfy.TableName = TableName.Project; notfy.TablePkId = recordId; notfy.Context = "AddComment"; await adamUnit.NotificationRepository.InserAsync(notfy); var Url = "/Admin/Project/Details?id=" + recordId; if (adamUnit.TokenFireBaseRepository.Exists(x => x.UserId == UserIdOfAdmin)) { var tokens = adamUnit.TokenFireBaseRepository.GetAll(x => x.UserId == UserIdOfAdmin).Select(x => x.token); foreach (var token in tokens) { NotificationController.SendPushNotification(token, notfy.Context, FirstName, Url, Attacment); } } return(Json(new { id = comment.Id, firstName = FirstName, lastName = LastName, attacment = Attacment, date = DateTime.Now.ToShortTimeString() })); } }
// Add comments public async Task <JsonResult> Comments(string data, long recordId) { var CurrentUserEmial = User.Identity.Name; var FirstName = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).FirstName; var LastName = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).LastName; var CurrentUserId = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).Id; if (User.IsInRole(AppHelper.SuperAdminEndUser)) { var Attacment = adamUnit.AttachmentRepository.SingleOrDefault(x => x.OwnerId == CurrentUserId).FileName; var comment = new Comment(); comment.TableId = recordId; comment.TableName = TableName.task; comment.context = data; comment.UserId = CurrentUserId; await adamUnit.CommentRepository.InserAsync(comment); var EmployeeId = adamUnit.TaskRepository.SingleOrDefault(x => x.Id == recordId).EmployeeId; var UserId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.Id == EmployeeId).UserId; var notify = new Notfication(); notify.OwnerUserId = CurrentUserId; notify.ToUserId = UserId; notify.TableName = TableName.task; notify.TablePkId = recordId; notify.Context = "Add comment"; await adamUnit.NotificationRepository.InserAsync(notify); var Url = "/Admin/task/Details?id=" + recordId; if (adamUnit.TokenFireBaseRepository.Exists(x => x.UserId == UserId)) { var tokens = adamUnit.TokenFireBaseRepository.GetAll(x => x.UserId == UserId).Select(x => x.token); foreach (var token in tokens) { NotificationController.SendPushNotification(token, notify.Context, FirstName, Url, Attacment); } } return(Json(new { id = comment.Id, firstName = FirstName, lastName = LastName, attacment = Attacment, date = DateTime.Now.ToShortTimeString() })); } else { var employeeId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.UserId == CurrentUserId).Id; var Attacment = adamUnit.AttachmentRepository.SingleOrDefault(x => x.OwnerId == employeeId.ToString()).FileName; // Retrive UserId of Role var UserIdOfAdmin = adamUnit.RoleRepository.GetUserIdOfRole(); var comment = new Comment(); comment.TableId = recordId; comment.TableName = TableName.task; comment.context = data; comment.UserId = CurrentUserId; await adamUnit.CommentRepository.InserAsync(comment); var notify = new Notfication(); notify.OwnerUserId = CurrentUserId; notify.ToUserId = UserIdOfAdmin; notify.TableName = TableName.task; notify.TablePkId = recordId; notify.Context = "Add comment"; await adamUnit.NotificationRepository.InserAsync(notify); var Url = "/Admin/task/Details?id=" + recordId; if (adamUnit.TokenFireBaseRepository.Exists(x => x.UserId == UserIdOfAdmin)) { var tokens = adamUnit.TokenFireBaseRepository.GetAll(x => x.UserId == UserIdOfAdmin).Select(x => x.token); foreach (var token in tokens) { NotificationController.SendPushNotification(token, notify.Context, FirstName, Url, Attacment); } } return(Json(new { id = comment.Id, firstName = FirstName, lastName = LastName, attacment = Attacment, date = DateTime.Now.ToShortTimeString() })); } }
public async Task <IActionResult> Create(List <IFormFile> files, ProjectVM projectVm) { if (!adamUnit.ProjectRepository.Exists(x => x.Name == projectVm.Name)) { // Current login User Information var CurrentUserEmial = User.Identity.Name; var CurrentUserId = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).Id; var CurrentName = adamUnit.AppUserRepository.SingleOrDefault(x => x.Email == CurrentUserEmial).FirstName; if (!ModelState.IsValid) { return(View(projectVm)); } var project = new Models.Project(); project = projectVm.ToEntity(); await adamUnit.ProjectRepository.InserAsync(project); var ProjId = project.Id; //save UserInProjUser string[] array = Regex.Split(projectVm.EmpIds, ","); foreach (var item in array) { var ProjUser = new ProjectUser(); ProjUser.ProjectId = ProjId; ProjUser.UserId = Convert.ToInt64(item); await adamUnit.ProjectUserRepository.InserAsync(ProjUser); } string webRootPath = _hostingEnvironment.WebRootPath; var state = adamUnit.AttachmentRepository.OnPostUpload(files, ProjId.ToString(), AttachmentOwner.Projects, AttachmentType.Photo, webRootPath); //send Notification To Users foreach (var item in array) { var UserId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.Id == Convert.ToInt16(item)).UserId; var UserName = adamUnit.AppUserRepository.SingleOrDefault(x => x.Id == UserId).UserName; var attachment = adamUnit.AttachmentRepository.FirstOrDefault(x => x.OwnerId == item).FileName; var notify = new Notfication(); notify.OwnerUserId = CurrentUserId; notify.ToUserId = UserId; notify.TableName = TableName.Project; notify.TablePkId = ProjId; notify.Context = "AddyouToProject"; var Url = "/Admin/Project/Details?id=" + ProjId; await adamUnit.NotificationRepository.InserAsync(notify); if (adamUnit.TokenFireBaseRepository.Exists(x => x.UserId == UserId)) { var tokens = adamUnit.TokenFireBaseRepository.GetAll(x => x.UserId == UserId).Select(x => x.token); foreach (var token in tokens) { NotificationController.SendPushNotification(token, notify.Context, CurrentName, Url, attachment); } } } TempData["SuccessMessage"] = "Created Successfully"; return(RedirectToAction(nameof(Index))); } ViewBag.Name = "Name is Exist Already"; ViewBag.Customer = adamUnit.CustomerRepository.GetAll().ToList(); ViewBag.Employee = adamUnit.EmployeeRepository.GetAllInclude().ToList(); return(View(projectVm)); }