public async Task <Event> AddAsync(Event Event) { context.Event.Add(Event); await context.SaveChangesAsync(); return(Event); }
public async Task <Information> AddAsync(Information Information) { context.Information.Add(Information); await context.SaveChangesAsync(); return(Information); }
public async Task <Address> AddAsync(Address Address) { context.Address.Add(Address); await context.SaveChangesAsync(); return(Address); }
public async Task <Exhibition> AddAsync(Exhibition Exhibition) { context.Exhibition.Add(Exhibition); await context.SaveChangesAsync(); return(Exhibition); }
public async Task <Colors> AddAsync(Colors Colors) { context.Color.Add(Colors); await context.SaveChangesAsync(); return(Colors); }
public async Task <Comment> AddAsync(Comment Comment) { context.Comment.Add(Comment); await context.SaveChangesAsync(); return(Comment); }
public async Task <Ceremony> AddAsync(Ceremony Cermoney) { context.Cermoney.Add(Cermoney); await context.SaveChangesAsync(); return(Cermoney); }
public async Task <Place> AddAsync(Place Place) { context.Place.Add(Place); await context.SaveChangesAsync(); return(Place); }
public async Task <Report> AddAsync(Report Reports) { context.Report.Add(Reports); await context.SaveChangesAsync(); return(Reports); }
public async Task SendUpdateToUser(WebNotification notification) { string userId = Context.GetHttpContext().User.FindFirst("sub")?.Value ?? "NoUser"; string userTimeZone = Context.GetHttpContext().User.FindFirst("timezone")?.Value ?? "Romance Standard Time"; // Todo: Check if sender has access rights to send to receiver. if (userId != "NoUser") { UserInfo userinfo; if (notification.To.Contains('@')) { userinfo = await _progenyHttpClient.GetUserInfo(notification.To); notification.To = userinfo.UserId; } else { userinfo = await _progenyHttpClient.GetUserInfoByUserId(notification.To); } notification.From = userId; if (!String.IsNullOrEmpty(userinfo.ProfilePicture)) { notification.Icon = userinfo.ProfilePicture; } else { notification.Icon = "/photodb/profile.jpg"; } notification.DateTime = DateTime.UtcNow; await _context.WebNotificationsDb.AddAsync(notification); await _context.SaveChangesAsync(); WebNotification webNotification = new WebNotification(); webNotification.Title = "Notification Sent to " + notification.To; webNotification.Message = ""; webNotification.From = Constants.AppName; webNotification.Type = "Notification"; webNotification.DateTime = DateTime.UtcNow; webNotification.DateTime = TimeZoneInfo.ConvertTimeFromUtc(webNotification.DateTime, TimeZoneInfo.FindSystemTimeZoneById(userTimeZone)); webNotification.DateTimeString = webNotification.DateTime.ToString("dd-MMM-yyyy HH:mm"); if (String.IsNullOrEmpty(webNotification.Link)) { webNotification.Link = "/Notifications?Id=" + webNotification.Id; } await Clients.Caller.SendAsync("ReceiveMessage", JsonConvert.SerializeObject(webNotification)); } }
public async Task <IActionResult> Create([Bind("Id,Name,PushEndpoint,PushP256DH,PushAuth")] PushDevices devices) { if (ModelState.IsValid) { string userId = HttpContext.User.FindFirst("sub").Value; devices.Name = userId; _context.Add(devices); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(devices)); }
public async Task <NotPublished> AddAsync(NotPublished NotPublished) { context.NotPublished.Add(NotPublished); await context.SaveChangesAsync(); return(NotPublished); }
public static async Task UpdateScCompInfoAsync() { using (var db = new WebDbContext()) { var compinfo = await db.ScCompInfoes.FindAsync(6); if (compinfo != null) { compinfo.CompNm = "업데이트111"; } else { var comp = new ScCompInfo { Addr1 = "테스트업데이트주소", CompNm = "업데이트당ㅇ앙아앙아", CompType = "A" }; db.ScCompInfoes.Add(comp); } await db.SaveChangesAsync(); } }
public async Task <EventResultBank> AddAsync(EventResultBank TranctionEvent) { context.TranctionEvent.Add(TranctionEvent); await context.SaveChangesAsync(); return(TranctionEvent); }
/// <summary> /// 异步新增数据 /// </summary> /// <param name="entity">实体</param> /// <returns></returns> public async Task <TEntity> AddAsync(TEntity entity) { var result = (await DbSet.AddAsync(entity)).Entity; await dbContext.SaveChangesAsync(); return(result); }
public async Task <IActionResult> SendAdminMessage(WebNotification notification) { // Todo: Implement Admin as role instead string userId = User.FindFirst("sub")?.Value ?? "NoUser"; string userEmail = User.FindFirst("email")?.Value ?? "NoUser"; string userTimeZone = User.FindFirst("timezone")?.Value ?? "NoUser"; if (userEmail.ToUpper() != _adminEmail.ToUpper()) { return(RedirectToAction("Index", "Home")); } if (userEmail.ToUpper() == _adminEmail.ToUpper()) { if (notification.To == "OnlineUsers") { notification.DateTime = DateTime.UtcNow; notification.DateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(userTimeZone)); notification.DateTimeString = notification.DateTime.ToString("dd-MMM-yyyy HH:mm"); await _hubContext.Clients.All.SendAsync("ReceiveMessage", JsonConvert.SerializeObject(notification)); } else { UserInfo userinfo; if (notification.To.Contains('@')) { userinfo = await _progenyHttpClient.GetUserInfo(notification.To); notification.To = userinfo.UserId; } else { userinfo = await _progenyHttpClient.GetUserInfoByUserId(notification.To); } notification.DateTime = DateTime.UtcNow; await _context.WebNotificationsDb.AddAsync(notification); await _context.SaveChangesAsync(); await _hubContext.Clients.User(userinfo.UserId).SendAsync("ReceiveMessage", JsonConvert.SerializeObject(notification)); WebNotification webNotification = new WebNotification(); webNotification.Title = "Notification Sent"; webNotification.Message = "To: " + notification.To + "<br/>From: " + notification.From + "<br/><br/>Message: <br/>" + notification.Message; webNotification.From = Constants.AppName + " Notification System"; webNotification.Type = "Notification"; webNotification.DateTime = DateTime.UtcNow; webNotification.DateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); webNotification.DateTimeString = webNotification.DateTime.ToString("dd-MMM-yyyy HH:mm"); await _hubContext.Clients.User(userId).SendAsync("ReceiveMessage", JsonConvert.SerializeObject(webNotification)); } } notification.Title = "Notification Added"; return(View(notification)); }
public async Task SendMessage(string user, string title, string message, string link, string tag) { PushNotification notification = new PushNotification(); notification.Title = title; notification.Message = message; notification.Link = link; notification.Tag = tag; var payload = JsonConvert.SerializeObject(notification); string vapidPublicKey = _configuration["VapidPublicKey"]; string vapidPrivateKey = _configuration["VapidPrivateKey"]; var deviceList = await _context.PushDevices.Where(m => m.Name == user).ToListAsync(); if (deviceList.Any()) { foreach (PushDevices dev in deviceList) { var pushSubscription = new PushSubscription(dev.PushEndpoint, dev.PushP256DH, dev.PushAuth); var vapidDetails = new VapidDetails("mailto:" + Constants.SupportEmail, vapidPublicKey, vapidPrivateKey); if (String.IsNullOrEmpty(dev.PushAuth) || String.IsNullOrEmpty(dev.PushEndpoint)) { _context.PushDevices.Remove(dev); await _context.SaveChangesAsync(); } else { var webPushClient = new WebPushClient(); try { webPushClient.SendNotification(pushSubscription, payload, vapidDetails); } catch (WebPushException ex) { if (ex.Message == "Subscription no longer valid") { _context.PushDevices.Remove(dev); await _context.SaveChangesAsync(); } } } } } }
public async Task <IActionResult> SetUnread(int Id) { string userId = User.FindFirst("sub")?.Value ?? "NoUser"; WebNotification updateNotification = await _context.WebNotificationsDb.SingleOrDefaultAsync(n => n.Id == Id); if (updateNotification != null) { if (userId == updateNotification.To) { updateNotification.IsRead = false; _context.WebNotificationsDb.Update(updateNotification); await _context.SaveChangesAsync(); await _hubContext.Clients.User(userId).SendAsync("UpdateMessage", JsonConvert.SerializeObject(updateNotification)); } } return(Ok()); }
public static async void UpdateCompInfoMultiAsync() { using (var db = new WebDbContext()) { var comps = db.ScCompInfoes.Where(ci => ci.CompType == "A" && ci.CompNm == "test113").ToList(); comps.ForEach(cis => { cis.Email = "*****@*****.**"; }); await db.SaveChangesAsync(); } }
public static async void insertScCompInfoAsync() { var comp = new ScCompInfo { Addr1 = "테스트주소", CompNm = "테스트회사", CompType = "A" }; using (var db = new WebDbContext()) { db.ScCompInfoes.Add(comp); //이것도 가능 //db.Entry<ScCompInfo>(comp).State = System.Data.Entity.EntityState.Added; await db.SaveChangesAsync(); } }
public async Task <IActionResult> DeleteProgeny(Progeny model) { string userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser; UserInfo userinfo = await _progenyHttpClient.GetUserInfo(userEmail); Progeny prog = await _progenyHttpClient.GetProgeny(model.Id); if (!prog.IsInAdminList(userinfo.UserEmail)) { // Todo: Show no access info. return(RedirectToAction("Index")); } List <Picture> photoList = await _mediaHttpClient.GetPictureList(model.Id, (int)AccessLevel.Private, userinfo.Timezone); if (photoList.Any()) { foreach (Picture picture in photoList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == picture.PictureId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Photo); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } await _mediaHttpClient.DeletePicture(picture.PictureId); } } List <Video> videoList = await _mediaHttpClient.GetVideoList(model.Id, 0, userinfo.Timezone); if (videoList.Any()) { foreach (Video video in videoList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == video.VideoId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Video); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } await _mediaHttpClient.DeleteVideo(video.VideoId); } } List <CalendarItem> eventsList = _context.CalendarDb.Where(e => e.ProgenyId == model.Id).ToList(); if (eventsList.Any()) { foreach (CalendarItem evt in eventsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == evt.EventId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Calendar); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.CalendarDb.Remove(evt); await _context.SaveChangesAsync(); } } List <VocabularyItem> vocabList = _context.VocabularyDb.Where(v => v.ProgenyId == model.Id).ToList(); if (vocabList.Any()) { foreach (VocabularyItem voc in vocabList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == voc.WordId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Vocabulary); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.VocabularyDb.Remove(voc); await _context.SaveChangesAsync(); } } List <Skill> skillList = _context.SkillsDb.Where(s => s.ProgenyId == model.Id).ToList(); if (skillList.Any()) { foreach (Skill skill in skillList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == skill.SkillId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Skill); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.SkillsDb.Remove(skill); await _context.SaveChangesAsync(); } } List <Friend> friendsList = _context.FriendsDb.Where(f => f.ProgenyId == model.Id).ToList(); if (friendsList.Any()) { foreach (Friend friend in friendsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == friend.FriendId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Friend); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } if (!friend.PictureLink.ToLower().StartsWith("http")) { await _imageStore.DeleteImage(friend.PictureLink); } _context.FriendsDb.Remove(friend); await _context.SaveChangesAsync(); } } List <Measurement> measurementsList = _context.MeasurementsDb.Where(m => m.ProgenyId == model.Id).ToList(); if (measurementsList.Any()) { foreach (Measurement measurement in measurementsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == measurement.MeasurementId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Measurement); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.MeasurementsDb.Remove(measurement); await _context.SaveChangesAsync(); } } List <Sleep> sleepList = _context.SleepDb.Where(s => s.ProgenyId == model.Id).ToList(); if (sleepList.Any()) { foreach (Sleep sleep in sleepList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == sleep.SleepId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Sleep); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.SleepDb.Remove(sleep); await _context.SaveChangesAsync(); } } List <Note> notesList = _context.NotesDb.Where(n => n.ProgenyId == model.Id).ToList(); if (notesList.Any()) { foreach (Note note in notesList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == note.NoteId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Note); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } // Todo: Delete content add from notes _context.NotesDb.Remove(note); await _context.SaveChangesAsync(); } } List <Contact> contactsList = _context.ContactsDb.Where(c => c.ProgenyId == model.Id).ToList(); if (contactsList.Any()) { foreach (Contact contact in contactsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == contact.ContactId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Contact); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.ContactsDb.Remove(contact); if (contact.AddressIdNumber != null) { Address address = await _context.AddressDb.SingleAsync(a => a.AddressId == contact.AddressIdNumber); _context.AddressDb.Remove(address); } await _context.SaveChangesAsync(); if (!contact.PictureLink.ToLower().StartsWith("http")) { await _imageStore.DeleteImage(contact.PictureLink); } } } List <Vaccination> vaccinationsList = _context.VaccinationsDb.Where(v => v.ProgenyId == model.Id).ToList(); if (vaccinationsList.Any()) { foreach (Vaccination vaccination in vaccinationsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == vaccination.VaccinationId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Vaccination); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.VaccinationsDb.Remove(vaccination); await _context.SaveChangesAsync(); } } await _progenyHttpClient.DeleteProgeny(model.Id); return(RedirectToAction("Index")); }
public async Task Create(TEntity entity) { await context.Set <TEntity>().AddAsync(entity); await context.SaveChangesAsync(); }