public async Task <IActionResult> CheckUpdateStatus() { var interval = _context.SysParam.FirstOrDefault(x => x.ParamCode == "DEFAULT_PRODUCT_INTERVAL").ParamValue; var products = _context.Product .Include(x => x.Poster) .Where(x => x.IsActive && x.UpdatedDate.AddSeconds(int.Parse(interval)).CompareTo(DateTime.UtcNow) < 1) .ToList(); if (products == null) { return(Ok()); } foreach (var item in products) { // var interval = int.Parse(item.UpdateIntervalInSecond); // var dateTimeProduct = item.UpdatedDate; // var dateTimeNow = DateTime.UtcNow; // dateTimeProduct.AddSeconds(interval); // var compare = dateTimeProduct.CompareTo(dateTimeNow); item.IsActive = false; _context.Product.Update(item); NotificationRequest notif = new NotificationRequest() { Body = item.ProductName + " is diactivated, please update your product to make it active again", Title = "Update Product", }; Notification newNotif = new Notification(notif) { To = item.Poster.Id, ModuleId = item.Id, ModuleName = "product", ModuleUseCase = "expired", PushDate = DateTime.UtcNow }; _context.Notification.Add(newNotif); if (item.Poster.PushId != null) { NotificationRequestToTopic body = new NotificationRequestToTopic(notif, item.Poster.PushId); body.data.notId = item.Id; string jsonBody = JsonConvert.SerializeObject(body); PushNotificationService.sendPushNotification(jsonBody); } } await _context.SaveChangesAsync(); return(Ok(products.Count() + " product need to be updated")); }
public async Task UnRegister(string connectionId) { var user = _dbcontext.MUser.FirstOrDefault(x => x.SocketId == connectionId); if (user != null) { user.SocketId = null; _dbcontext.MUser.Update(user); await _dbcontext.SaveChangesAsync(); } }
public async Task <IActionResult> DeleteProduct(int?id) { if (id == null) { return(BadRequest()); } var product = await _context.Product.FirstOrDefaultAsync(x => x.Id == id); var foto = await _context.FotoUpload.FirstOrDefaultAsync(x => x.ProductId == id); var interaction = _context.Interaction.Where(x => x.ProductId == id); _context.Remove(foto); _context.Remove(product); _context.Remove(interaction); await _context.SaveChangesAsync(); return(Ok()); }