public async Task <MessageAndStatus> Register(string userName, string password, LoginType loginType = LoginType.Local) { var user = new UserEntity { EmailAddress = userName, Password = password, LoginType = (byte)loginType }; UserRolesEntity userRoles = new UserRolesEntity { User = user, RoleId = 1 }; _context.Add(userRoles); try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(new MessageAndStatus { Status = "ERROR", Message = "" }); } return(new MessageAndStatus { Status = "OK", Message = await GenerateToken2(user.UserId) }); // Ok(await GenerateAccessTokenAsync(user.UserId)); }
public async Task <ActionResult <ListAggregator> > AddListAggregatortoListt(int parentId, [FromBody] ListAggregator item) { var listItemEntity = _mapper.Map <ListAggregatorEntity>(item); //listItemEntity.ListAggregatorId = parentId; var userListAggregatorEntity = new UserListAggregatorEntity { UserId = parentId, ListAggregator = listItemEntity, PermissionLevel = 1 }; _context.UserListAggregators.Add(userListAggregatorEntity); await _context.SaveChangesAsync(); //var item = _mapper.Map<ListItem>(listItemEntity); item.ListAggregatorId = listItemEntity.ListAggregatorId; return(await Task.FromResult(item)); }
public async Task <ActionResult <MessageAndStatus> > GetInvitationsList(string userName) { var list_Invi_Aggr = from invi in _context.Invitations where invi.EmailAddress == userName join aggr in _context.ListAggregators on invi.ListAggregatorId equals aggr.ListAggregatorId into invi_aggr from aggrOrNull in invi_aggr.DefaultIfEmpty() select new { Invitation = invi, ListAggr = aggrOrNull }; // List<InvitationEntity> toDeleteEntity = new List<InvitationEntity>(); foreach (var item in list_Invi_Aggr) { if (item.ListAggr == null) { _context.Remove(item.Invitation); //toDeleteEntity.Add(item.Invitation); } } await _context.SaveChangesAsync(); var listInviAggr = await list_Invi_Aggr.ToListAsync(); var invitationsList = listInviAggr.Select(a => { var inv = _mapper.Map <Invitation>(a.Invitation); inv.ListAggregatorName = a.ListAggr.ListAggregatorName; return(inv); }).ToList(); return(new MessageAndStatus { Status = "OK", Message = JsonConvert.SerializeObject(invitationsList) }); }
public async Task <ActionResult <ListItem> > AddListItemToListt(int parentId, [FromBody] ListItem item, int listAggregationId) { //Task task = WebApiHelper.SendMessageToUserAsync(listAggregationId, _context, _hubConnection); if (!CheckIntegrityList(parentId, listAggregationId)) { return(Forbid()); } var listItemEntity = _mapper.Map <ListItemEntity>(item); listItemEntity.ListId = parentId; _context.ListItems.Add(listItemEntity); try { await _context.SaveChangesAsync(); } catch (Exception ex) { } //var item = _mapper.Map<ListItem>(listItemEntity); item.ListItemId = listItemEntity.ListItemId; //task.GetAwaiter().GetResult(); var userList = await WebApiHelper.GetuUserIdFromListAggrIdAsync(listAggregationId, _context); //await _signarRService.SendRefreshMessageToUsersAsync(userList, "Add_ListItem", listItemEntity.ListItemId, listAggregationId, parentId); await _mediator.Publish( new AddEditSaveDeleteListItemEvent(userList, "Add_ListItem", listItemEntity.ListItemId, listAggregationId, parentId)); return(await Task.FromResult(item)); }
public async Task <ActionResult <bool> > ChangeOrderListItem([FromBody] IEnumerable <List> items) { var listItemEntity = _mapper.Map <IEnumerable <ListEntity> >(items); // _context.ListItems.Remove(_context.ListItems.Single(a => a.ListItemId == ItemId)); foreach (var item in listItemEntity) { _context.Entry <ListEntity>(item).Property(nameof(ListEntity.Order)).IsModified = true; } var amount = await _context.SaveChangesAsync(); // var listItem = _mapper.Map<ListItem>(listItemEntity); return(await Task.FromResult(true)); }
public async Task <MessageAndStatusAndData <ListItem> > Handle(SavePropertyCommand request, CancellationToken cancellationToken) { if (!CheckIntegrityListItem(request.Item.ListItemId, request.ListAggregationId)) { return(await Task.FromResult(MessageAndStatusAndData.Fail <ListItem>("Forbbidden"))); } var listItemEntity = _mapper.Map <ListItemEntity>(request.Item); _context.Entry <ListItemEntity>(listItemEntity).Property(request.PropertyName).IsModified = true; var amount = await _context.SaveChangesAsync(); var listItem = _mapper.Map <ListItem>(listItemEntity); return(await Task.FromResult(MessageAndStatusAndData.Ok(listItem, "OK"))); }