public async Task <IActionResult> PutChatItem(int id, ChatItem chatItem) { if (id != chatItem.Id) { return(BadRequest()); } _context.Entry(chatItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ChatItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UpdateUser(int id, [FromBody] UserForUpdateDto userForUpdateDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); var userFromRepo = await _context.Users.FirstOrDefaultAsync(u => u.Id == id); if (userFromRepo == null) { return(NotFound($"Could not find the user with id = {id}")); } if (currentUserId != userFromRepo.Id) { return(Unauthorized()); } _mapper.Map(userForUpdateDto, userFromRepo); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> PutUser(string id, User user) { if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutResposta(int id, Resposta resposta) { if (id != resposta.Id) { return(BadRequest()); } _context.Entry(resposta).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RespostaExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <bool> Insert(UserModel x) { var user = new Data.Entities.Users { FirstName = x.FirstName, LastName = x.LastName, Address = x.Address, BirthDate = x.BirthDate, ContactNumber = x.ContactNumber, Email = x.Email, Password = x.Password, Height = x.Height, Weight = x.Weight, RoleId = x.RoleId }; _context.Users.Add(user); await _context.SaveChangesAsync(); return(true); }
public async Task <bool> Insert(NoticeModel model) { var notice = new NoticeBoard { Name = model.Name, NoticeDateTime = model.NoticeDateTime, Description = model.Description }; _context.NoticeBoards.Add(notice); await _context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Create([Bind("Id,Name")] MailList mailList) { if (ModelState.IsValid) { mailList.OwnerEmail = User.FindFirst(ClaimTypes.Name).Value; _context.Add(mailList); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mailList)); }
public async Task <bool> Insert(RoleModel model) { var role = new Data.Entities.Role { Id = model.Id, Name = model.Name }; _context.Roles.Add(role); await _context.SaveChangesAsync(); return(true); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,DueDate,MailList")] Assignment assignment) { if (ModelState.IsValid) { assignment.OwnerEmail = User.FindFirst(ClaimTypes.Name).Value; _context.Add(assignment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MailList"] = new SelectList(_context.MailLists, "Id", "Name", assignment.MailList); return(View(assignment)); }
public async Task <ActionResult <Meeting> > PostMeeting(Meeting meeting) { _context.Meeting.Add(meeting); await _context.SaveChangesAsync(); return(Ok(meeting)); }
public async Task <bool> AddDefaultBotResponseAsync(DefaultBotResponse resp) { try { await _dbContext.DefaultBotResponses.AddAsync(resp); await _dbContext.SaveChangesAsync(); _logger.LogInformation("Default bot response ({resp.Id}) was added", resp.Id); return(true); } catch (Exception ex) { _logger.LogError(ex, "can't add default bot response"); return(false); } }
public async Task Create(Operator item) { if (await _context.Operators.AllAsync(o => o.Login != item.Login)) { _context.Operators.Add(item); await _context.SaveChangesAsync(); } }
public async Task Create(MessageInfo item) { var lastMess = await _context.MessageInfos.LastOrDefaultAsync(); timeControl.SetParent(item, lastMess?.Id + 1 ?? 1); _context.MessageInfos.Add(item); await _context.SaveChangesAsync(); }
public async Task <IActionResult> UpdateProject([FromBody] TheProjectDto prj) { if (!HasAccess(prj.OwnerId)) { return(StatusCode(403)); } var prjFromDb = _dbContext.TheProjects.FirstOrDefault(p => p.Id == prj.Id); if (prjFromDb == null) { return(NotFound("No such project in database")); } var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(prj, null, null); var validationResults = new List <ValidationResult>(); Validator.TryValidateObject(prj, validationContext, validationResults, true); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var prjObj = _mapper.Map <TheProject>(prj); _dbContext.Entry(prjFromDb).CurrentValues.SetValues(prjObj); await _dbContext.SaveChangesAsync(); _logger.LogInformation("Project ({prj.Id}) updated", prj.Id); return(Ok()); } catch (Exception ex) { _logger.LogError(ex, "Cant't update project ({prj.Id})", prj.Id); return(BadRequest()); } }
public async Task <User> Register(User user, string password) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }
public async Task <IActionResult> AddGreeting([FromBody] GreetingDto greeting) { var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(greeting, null, null); var validationResults = new List <ValidationResult>(); Validator.TryValidateObject(greeting, validationContext, validationResults, true); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var prj = _dbContext.TheProjects.FirstOrDefault(p => p.Id == greeting.ProjectId); if (prj == null) { return(NotFound("There is no such project in db")); } if (!HasAccess(prj.OwnerId)) { return(StatusCode(403)); } try { var greetingObj = _mapper.Map <Greeting>(greeting); _dbContext.Greetings.Add(greetingObj); await _dbContext.SaveChangesAsync(); _logger.LogInformation("Greeting ({greetingObj.Id}) created", greetingObj.Id); return(StatusCode(201)); } catch (Exception ex) { _logger.LogError(ex, "Cant't add greeting to project ({projectId})", greeting.ProjectId); return(BadRequest()); } }
public async Task Create(RegistredUser item) { var user = await _context.Users.FirstOrDefaultAsync(u => u.Phone == item.Phone); if (user == null) { _context.RegistredUsers.Add(item); } else { _context.Users.Remove(user); _context.RegistredUsers.Add(item); _context.MessageInfos.Where(m => m.User.Id == user.Id).AsParallel().ForAll(m => m.User = item); } await _context.SaveChangesAsync(); }
public async Task <bool> Insert(QuestionAnswerModel model) { var question = new Data.Entities.QuestionAnswer { NoticeBoardId = model.NoticeBoardId, QuestionHint1 = model.QuestionHint1, QuestionHint2 = model.QuestionHint2, QuestionHint3 = model.QuestionHint3, Answer = model.Answer }; question.File = new StaticMedia { ContentLength = model.File.ContentLength, ContentType = model.File.ContentType, FileName = model.File.FileName, InputStream = model.FileInputStream }; _context.QuestionAnswers.Add(question); await _context.SaveChangesAsync(); return(true); }
private async Task ScheduleAssignmentAsync(AssignmentDTO assignmentFromLex) { var mailList = await _context.MailLists .Where(m => m.Name.Contains(assignmentFromLex.MailList)) .Include(m => m.Emails) .FirstOrDefaultAsync(); foreach (var email in mailList.Emails) { await _emailSender.SendEmailAsync(email.Address, $"{assignmentFromLex.Title} {DateTime.Now.ToString()}", assignmentFromLex.Description); } var assignment = new Assignment { Title = assignmentFromLex.Title, Description = assignmentFromLex.Description, DueDate = DateTime.Parse(assignmentFromLex.DueDate), MailList = mailList.Id, OwnerEmail = User.FindFirst(ClaimTypes.Name).Value }; _context.Add(assignment); await _context.SaveChangesAsync(); }
public Task SaveChangeAsync() => _dbContext.SaveChangesAsync();
public async Task SaveAsync() { await _context.SaveChangesAsync(); }
public async Task Create(User item) { _context.Users.Add(item); await _context.SaveChangesAsync(); }