public static NotificationVm ToModel(this Notfication entity, AdamUnit adamUnit) { var NofiVM = new NotificationVm(); NofiVM.Id = entity.Id; NofiVM.Context = entity.Context; NofiVM.NameOfSend = adamUnit.AppUserRepository.SingleOrDefault(x => x.Id == entity.OwnerUserId).FirstName; var userIdAdmin = adamUnit.RoleRepository.GetUserIdOfRole(); if (userIdAdmin == entity.OwnerUserId) { NofiVM.filename = adamUnit.AttachmentRepository.FirstOrDefault(x => x.OwnerId == userIdAdmin.ToString() && x.AttachmentOwner == AttachmentOwner.Employees).FileName; } else { var employeeId = adamUnit.EmployeeRepository.SingleOrDefault(x => x.UserId == entity.OwnerUserId).Id; NofiVM.filename = adamUnit.AttachmentRepository.SingleOrDefault(x => x.OwnerId == employeeId.ToString() && x.AttachmentOwner == AttachmentOwner.Employees).FileName; } NofiVM.TableName = entity.TableName.GetDisplayName(); NofiVM.TablePkId = entity.TablePkId; NofiVM.IsRead = entity.IsRead; NofiVM.Date = entity.CreationDate.ToShortTimeString(); return(NofiVM); }
public async Task SendOrderReciveNotifcation(IEnumerable <Order> orders) { var moneyPlacedes = await _uintOfWork.Repository <MoenyPlaced>().GetAll(); var outSideCompny = moneyPlacedes.First(c => c.Id == (int)MoneyPalcedEnum.OutSideCompany).Name; List <Notfication> totalNotfications = new List <Notfication>(); List <Notfication> detailNotifications = new List <Notfication>(); foreach (Order order in orders) { if (order.OrderStateId != (int)OrderStateEnum.Finished && order.OrderplacedId != (int)OrderplacedEnum.Way) { var clientNotigaction = totalNotfications.Where(c => c.ClientId == order.ClientId && c.OrderPlacedId == order.OrderplacedId && c.MoneyPlacedId == order.MoenyPlacedId).FirstOrDefault(); if (clientNotigaction == null) { int moenyPlacedId = order.MoenyPlacedId; if (moenyPlacedId == (int)MoneyPalcedEnum.WithAgent) { moenyPlacedId = (int)MoneyPalcedEnum.OutSideCompany; } clientNotigaction = new Notfication() { ClientId = order.ClientId, OrderPlacedId = order.OrderplacedId, MoneyPlacedId = moenyPlacedId, IsSeen = false, OrderCount = 1 }; totalNotfications.Add(clientNotigaction); } else { clientNotigaction.OrderCount++; } } var moneyPlacedName = order.MoenyPlaced.Name; if (order.MoenyPlacedId == (int)MoneyPalcedEnum.WithAgent) { moneyPlacedName = outSideCompny; } detailNotifications.Add(new Notfication() { Note = $"الطلب {order.Code} اصبح {order.Orderplaced.Name} و موقع المبلغ {order.MoenyPlaced.Name}", ClientId = order.ClientId }); } await _uintOfWork.AddRange(detailNotifications); await _uintOfWork.AddRange(totalNotfications); var unionNotification = totalNotfications.Union(detailNotifications); var grouping = unionNotification.GroupBy(c => c.ClientId); foreach (var item in grouping) { var key = item.Key.ToString(); var notficationDtos = item.Select(c => _mapper.Map <NotificationDto>(c)); await _notificationHub.AllNotification(key.ToString(), notficationDtos.ToArray()); } }
public void AddNotfiaction(Notfication notfication) { Notfication[] newnotfication = new Notfication[++NotficationCount]; if (Notfications != null) { Notfications.CopyTo(newnotfication, 0); } newnotfication[newnotfication.Length - 1] = notfication; Notfications = newnotfication; }
public void searchPost(int id) { if (Posts != null) { foreach (var item in Posts) { if (id == item.Id) { ++item.WiewCount; Notfication notf = new Notfication { DateTime = DateTime.Now, FromUser = Helper.user.Username, Id = Helper.user.Id, Text = $"User {Helper.user.Username} saw Post" }; Helper.admin.AddNotfiaction(notf); item.Show(); Console.WriteLine("1)Like"); int choose = int.Parse(Console.ReadLine()); if (choose == 1) { ++item.LikeCount; Notfication notf1 = new Notfication { DateTime = DateTime.Now, FromUser = Helper.user.Username, Id = Helper.user.Id, Text = $"User {Helper.user.Username} liked Your Post", }; SendMail.SendMail1(); Helper.admin.AddNotfiaction(notf1); } Console.Clear(); item.Show(); break; } } } else { Console.ForegroundColor = ConsoleColor.Red; } }
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 <ErrorRepsonse <ClientDto> > GivePoints(GiveOrDiscountPointsDto giveOrDiscountPointsDto) { var client = await _uintOfWork.Repository <Client>().GetById(giveOrDiscountPointsDto.ClientId); await _uintOfWork.BegeinTransaction(); try { string sen = ""; if (giveOrDiscountPointsDto.IsGive) { client.Points += giveOrDiscountPointsDto.Points; sen += $"تم إهدائك {giveOrDiscountPointsDto.Points} نقاط"; } else { client.Points -= giveOrDiscountPointsDto.Points; sen += $"تم خصم {giveOrDiscountPointsDto.Points} نقاط منك"; } Notfication notfication = new Notfication() { ClientId = client.Id, Note = sen, }; await _uintOfWork.Repository <Client>().Update(client); await _uintOfWork.Repository <Notfication>().AddAsync(notfication); await _uintOfWork.Commit(); RemoveCash(); return(new ErrorRepsonse <ClientDto>() { Data = _mapper.Map <ClientDto>(client) }); } catch (Exception ex) { await _uintOfWork.RoleBack(); throw ex; } }
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)); }
// 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 <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() })); } }
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)); }
public NotificationStatus(Notfication notfication, string url = null, string content = null) { this.url = url; this.content = content; Notfication = notfication; }