/// <summary> /// Create group message. /// </summary> /// <param name="dto"> Object to be created. </param> /// <param name="userId">Id of a user creating the message. </param> /// <returns> Response containing created object (dto). </returns> public async Task <DtoResponseResult <DtoGroupMessage> > CreateAsync(DtoGroupMessage dto, int userId) { var entity = _mapper.Map <GroupMessage>(dto); entity.CreatedById = userId; entity.CreatedDate = DateTime.UtcNow; var newEntity = _unitOfWork.GroupMessageRepository.Create(entity); await _unitOfWork.SaveChangesAsync(); return(DtoResponseResult <DtoGroupMessage> .CreateResponse(_mapper.Map <DtoGroupMessage>(newEntity))); }
/// <summary> /// Update message of given id. /// </summary> /// <param name="dto"> Updated version of an object. </param> /// <param name="userId"> Id of a user updating message. </param> /// <returns> Response containing updated message (dto). </returns> public async Task <DtoResponseResult <DtoGroupMessage> > UpdateAsync(DtoGroupMessage dto, int userId) { var entity = await _unitOfWork.GroupMessageRepository.FindAsync(gm => gm.Id == dto.Id); if (entity == null) { return(DtoResponseResult <DtoGroupMessage> .FailedResponse("Group Message not found")); } _mapper.Map(dto, entity); entity.UpdatedById = userId; entity.UpdatedDate = DateTime.UtcNow; var newEntity = _unitOfWork.GroupMessageRepository.Update(entity, dto.Id); await _unitOfWork.SaveChangesAsync(); return(DtoResponseResult <DtoGroupMessage> .CreateResponse(_mapper.Map <DtoGroupMessage>(newEntity))); }