public ServiceResponse <List <MailReadModel> > List(int page, int pageSize) { var response = new ServiceResponse <List <MailReadModel> >(); var mailConverter = new MailConverter(); var serviceResponse = _mailService.ListForUser(page, pageSize, CurrentUser.ID); if (serviceResponse.IsSuccessed) { response.Data = mailConverter.ConvertReadModel(mailConverter.Convert(serviceResponse.Data)); } response.IsSuccessed = serviceResponse.IsSuccessed; return(response); }
public ServiceResponse <List <MailReadModel> > ListUnreadMails() { var response = new ServiceResponse <List <MailReadModel> >(); var serviceResponse = _mailService.ListUnreadMails(CurrentUser.ID); var mailConverter = new MailConverter(); if (serviceResponse.IsSuccessed) { response.Data = mailConverter.ConvertReadModel(mailConverter.Convert(serviceResponse.Data)); } response.IsSuccessed = serviceResponse.IsSuccessed; return(response); }
public ServiceResponse <MailCreateModel> Create([FromBody] MailCreateModel mailCreateRequestModel) { var response = new ServiceResponse <MailCreateModel>(); var toUser = _userService.GetByUserName(mailCreateRequestModel.ToUserName); if (toUser.Errors.Count == 0) { var model = new MailModel(); model.Content = mailCreateRequestModel.Content; model.Subject = mailCreateRequestModel.Subject; model.ToUserId = toUser.Data.ID; model.FromUserId = CurrentUser.ID; model.IsActive = true; model.IsDeleted = false; model.IsRead = false; var validationResult = _mailModelValidator.Validate(model); if (validationResult.IsValid) { var entity = new MailConverter().Convert(model); var serviceResponse = _mailService.Create(entity); response.IsSuccessed = serviceResponse.IsSuccessed; response.Errors = serviceResponse.Errors; response.Data = new MailCreateModel() { Content = model.Content, Subject = model.Subject, ToUserName = toUser.Data.UserName }; } else { _logger.Error("{source} {template} {logtype} {ValidationError}", "controller", "MailEntity", "validationerror", validationResult.Errors); response.IsSuccessed = false; response.Errors = new ValidationFailureConverter().Convert(validationResult.Errors.ToList()); } } else { response.Errors.Add(new ServiceError() { Code = "200003", InnerMessage = "To username is not found.", Message = "To username is not found." }); } return(response); }
public ServiceResponse <MailReadModel> Read(Guid guid) { var response = new ServiceResponse <MailReadModel>(); var entity = _mailService.Read(guid); if (entity.IsSuccessed) { var mailConverter = new MailConverter(); var responseData = mailConverter.Convert(entity.Data); responseData.FromUser = new UserConverter().Convert(_userService.Read(responseData.FromUserId).Data); responseData.ToUser = new UserConverter().Convert(_userService.Read(responseData.ToUserId).Data); response.Data = mailConverter.ConvertReadModel(responseData); if (!responseData.IsRead || responseData.ToUserId == CurrentUser.ID) { responseData.IsRead = true; var entityData = new MailConverter().Convert(responseData); _mailService.Update(entityData); } } response.IsSuccessed = response.IsSuccessed; return(response); }