public async Task <IHttpActionResult> Register([FromBody] RegisterBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newUser = _userRepository.Create(model.UserName, model.Password); _systemContext.SaveChanges(); var newEmployee = _employeeRepository.Create(newUser.Id); var newProfile = await _profileRepository.CreateAsync(newUser).ConfigureAwait(false); newUser.SetProfile(newProfile); _systemContext.SaveChanges(); _domainContext.SaveChanges(); /* * var identityResult = new IdentityResult(); * * if (!identityResult.Succeeded) * { * return GetErrorResult(identityResult); * } */ return(Ok()); }
public async Task <ProfileDto> CreateProfileAsync(ProfileUpsertDto profile) { var profileToCreate = mapper.Map <DomainModels.Profile>(profile); var createdProfile = await profileRepository.CreateAsync(profileToCreate); return(mapper.Map <ProfileDto>(createdProfile)); }
public async Task <int> CreateAsync(ProfileAdd model) { if (ValidateProfile(model) == false) { return(0); } if (model.SaleId <= 0) { model.SaleId = _process.User.Id; } model.Status = (int)ProfileStatus.Draft; var sqlmodel = _mapper.Map <ProfileAddSql>(model); var result = await _rpProfile.CreateAsync(sqlmodel, _process.User.Id); if (result.data > 0 && !string.IsNullOrWhiteSpace(model.Comment)) { var bzNot = _svProvider.GetService <INoteBusiness>(); await bzNot.AddNoteAsync(new Entities.Note.NoteAddRequest { Content = model.Comment, ProfileId = result.data, ProfileTypeId = (int)NoteType.Common }); } return(ToResponse(result)); }
public async Task <Result <Exception, Guid> > Handle(Command request, CancellationToken cancellationToken) { Result <Exception, Agent> agentVerify = await _agentRepository.GetByIdAsync(request.CompanyId, request.AgentId); if (agentVerify.IsFailure) { return(new DuplicateException("Agent não encontrado na empresa do usuário.")); } var userCallback = await _userRepository.GetByIdAsync(request.UserWhoCreatedId); if (userCallback.IsFailure) { return(new NotFoundException("Não foi encontrado um usúario com o id da requisição.")); } Profile profile = Mapper.Map <Command, Profile>(request); profile.ProfileIdentifier = Guid.NewGuid(); var items = _itemRepository.GetAll(request.AgentId); if (items.IsFailure) { return(items.Failure); } Result <Exception, Profile> callback = new BusinessException(ErrorCodes.ServiceUnavailable, "ocorreram falhas na criação do perfil"); foreach (var item in items.Success) { var pro = Mapper.Map <Profile, Profile>(profile); pro.Value = item.Value; pro.ItemId = item.Id; callback = await _repository.CreateAsync(pro); } if (callback.IsFailure) { return(callback.Failure); } Log log = new Log { UserId = request.UserWhoCreatedId, UserCompanyId = request.CompanyId, NewValue = $"{profile.Name}", OldValue = "Não existe", TargetId = profile.ProfileIdentifier, EntityType = ETypeEntity.AgentProfiles, TypeLogMethod = ETypeLogMethod.Create, CreatedIn = DateTime.Now }; await _logRepository.CreateAsync(log); return(profile.ProfileIdentifier); }
public async Task <Profile> UpdateProfileAsync([FromBody] Profile model) { if (model.Id == 0) { await _profileRepository.CreateAsync(model); return(model); } else { await _profileRepository.UpdateAsync(model.Id, model); return(model); } }
public async Task <Unit> Handle(CreateCommand request, CancellationToken cancellationToken) { var profile = new UserProfile( request.SSN, request.Email, new MobilePhone { CountryCode = request.CountryCode, Number = request.PhoneNumber }, new Domain.Users.Customer(request.CustomerId) ); var success = await _profileRepository.CreateAsync(profile, cancellationToken) > 0; if (success) { return(Unit.Value); } throw new RestException(System.Net.HttpStatusCode.InternalServerError, new { Message = "Problem saving changes" }); }
public async Task <IActionResult> ParseProfile(string link) { if (String.IsNullOrEmpty(link)) { return(StatusCode(StatusCodes.Status400BadRequest, "profile link")); } if (_vkApiService.AccessToken == "") { return(StatusCode(StatusCodes.Status500InternalServerError, "5 User authorization failed: access_token has expired.")); } string id = link.Split('/').Last(); string json; Profile profile; List <WallItem> wallItems; try { json = await _vkApiService.ResolveScreenNameAsync(id); dynamic res = JsonConvert.DeserializeObject(json); string type = res.response?.type; if (type == "application") { return(StatusCode(StatusCodes.Status500InternalServerError, "application profile")); } //получаем общие данные о странице json = await _vkApiService.GetProfileAsync(id, type); res = JsonConvert.DeserializeObject(json); string ProfileId = (string)res.response[0].id;; if (type == "group") { ProfileId = "-" + ProfileId; } profile = await _profiles.GetByIdAsync(ProfileId); //если такой профиль уже есть в бд, удаляем, для записи новых данных if (profile != null) { await _profiles.DeleteAsync(profile.Id); } profile = _parseVk.ParseProfile(json, type); //получаем записи со стены wallItems = _parseVk.ParseWall(await _vkApiService.GetWallAsync(profile.Id, 50)); //------------------------- // res = JsonConvert.DeserializeObject(await _vkApiService.GetSubscriptions(profile.Id)); // List<string> SubIds = res.response?.groups.items.ToObject<List<string>>(); // res = JsonConvert.DeserializeObject(await _vkApiService.GetNewsfeed(String.Join(',',SubIds))); //------------------- //полачаем все лайки //для ускорения используется метод execute, который может содержать до 25 запросов var likeUsers = new List <LikeUser>(); for (int i = 0; i < wallItems.Count; i = i + 12) { //делаем выборку по 12 записей, в итоге 24 запроса int count = wallItems.Count - i > 12 ? 12 : wallItems.Count - i; dynamic likes; //ограничение максимум 3 запроса в сек. await Task.Delay(350); //var likesJson = await _vkApiService.GetLikesAsync(profile.Id, item.ItemId, "post"); // var likesJson = await _vkApiService.GetLikeUsersAsync(profile.Id, item.ItemId, "post"); var likesJson = await _vkApiService.GetLikeUsersAsync(profile.Id, String.Join(',', wallItems.GetRange(i, count).Select(wi => wi.ItemId)), "post", 300); likes = JsonConvert.DeserializeObject(likesJson); Debug.WriteLine("wallItemsParseCount: " + i); // записываем в бд о пользователе и количестве лайков на стене foreach (var ul in likes.response) { var likeUser = likeUsers.FirstOrDefault(l => l.OwnerId == ul.id.ToString()); if (likeUser == null) { likeUser = new LikeUser { OwnerId = ul.id.ToString(), ProfileId = profile.Id, FullName = ul.first_name.ToString() + " " + ul.last_name.ToString(), PhotoUrl = ul.photo_100, LikeCount = 1 }; likeUsers.Add(likeUser); } else { likeUser.LikeCount++; Debug.WriteLine("yyyyy:"); } } } //------------------ profile.WallItems = wallItems; profile.LikeUsers = likeUsers; await _profiles.CreateAsync(profile); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } return(Ok(JsonConvert.SerializeObject(profile))); }