public async Task <IActionResult> PutOrder(int id, Order order) { if (id != order.OrderID) { return(BadRequest()); } _context.Entry(order).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> AddToFav(int id) { var favBikeStation = new Favoris(); favBikeStation.IDStation = id; _context.Favoris.Add(favBikeStation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task ReDeliverStuckMessage(Data.DataContext _context) { DateTime DeservedTimeForError = DateTime.Now.AddMinutes(-_config.ReDelivery.MaxTotalMinuteForError); DateTime DeservedTimeForInProducer = DateTime.Now.AddMinutes(-_config.ReDelivery.MaxTotalMinuteForInProducer); List <Message> stuckMessages = await _context.Messages.Where(m => (m.Status == MessageStatuses.ERROR && m.UpdatedAt <= DeservedTimeForError) || (m.Status == MessageStatuses.INPRODUCER && m.UpdatedAt <= DeservedTimeForInProducer)) .ToListAsync(); foreach (Message message in stuckMessages) { // stuck message, log it if (message.ReDeliveryTimes >= _config.ReDelivery.MaxRetryTimes) { using var transaction = _context.Database.BeginTransaction(); StuckMessage stuckMessage = _mapper.Map <StuckMessage>(message); stuckMessage.StuckReason = MessageStuckReasons.MAX_RETRY_EXCEED; await _context.StuckMessages.AddAsync(stuckMessage); _context.Messages.Remove(message); await _context.SaveChangesAsync(); transaction.Commit(); } else { await _queueService.ReScheduleMessage(message); } } }
private async Task <bool> PushTaskToHistory(History history) { try { await _context.AddAsync(history); await _context.SaveChangesAsync(); return(true); } catch (Exception ex) { return(false); throw; } }
public async Task <bool> ScheduleMessage(Message message) { try { message.Status = MessageStatuses.INPRODUCER; message.UpdatedAt = DateTime.Now; await _context.Messages.AddAsync(message); await _context.SaveChangesAsync(); // publish the message PublishMessage(message); return(true); } catch (DbUpdateException ex) when(ex.InnerException is SqlException sqlException && (sqlException.Number == 2627 || sqlException.Number == 2601)) { return(false); } }
public async Task <ActionResult <UserDto> > Register(RegisterDTO registerDTO) { if (await UserExists(registerDTO.Username)) { return(BadRequest("Username is taken")); } using var hmac = new HMACSHA512(); var user = new AppUser { UserName = registerDTO.Username.ToLower(), PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(registerDTO.Password)), PasswordSalt = hmac.Key }; _context.Users.Add(user); await _context.SaveChangesAsync(); return(new UserDto { Username = user.UserName, Token = _tokenService.CreateToken(user) }); }
private async Task <bool> AddMessageGroup(int roomid, string message, int userid, List <string> images) { try { var project = await _context.Projects.FirstOrDefaultAsync(x => x.Room.Equals(roomid)); var managers = await _context.Managers.Where(x => x.ProjectID.Equals(project.ID)).Select(x => x.UserID).ToListAsync(); var members = await _context.TeamMembers.Where(x => x.ProjectID.Equals(project.ID)).Select(x => x.UserID).ToListAsync(); var listAll = managers.Union(members); var listChats = new List <Chat>(); var listParticipants = new List <Participant>(); //Neu chua co participan thi them vao if (!await _context.Participants.AnyAsync(x => x.RoomID == roomid)) { foreach (var user in listAll) { listParticipants.Add(new Participant { UserID = user, RoomID = roomid }); } await _context.AddRangeAsync(listParticipants); } var chat = new Chat { Message = message, UserID = userid, ProjectID = project.ID, RoomID = roomid }; //add message userid await _context.AddAsync(chat); await _context.SaveChangesAsync(); if (images.Count > 0) { var imagesList = new List <UploadImage>(); foreach (var item in images) { imagesList.Add(new UploadImage { ChatID = chat.ID, Image = item }); } await _context.AddRangeAsync(imagesList); await _context.SaveChangesAsync(); } return(true); } catch { return(false); throw; } throw new NotImplementedException(); }