Exemplo n.º 1
0
        public async Task <IActionResult> Create(BeingModel model)
        {
            string userId = HttpContext.User.FindUserId();

            if (userId == null)
            {
                return(Unauthorized());
            }

            if (!await freeLimits.CanCreateBeingAsync(userId))
            {
                return(PremiumRequired());
            }

            Being entity = new Being();

            MapModelToEntity(model, entity);
            entity.UserId  = userId;
            entity.Created = DateTime.Now;

            await db.Beings.AddAsync(entity);

            await db.SaveChangesAsync();

            MapEntityToModel(entity, model);
            return(CreatedAtAction(nameof(Get), new { id = entity.Id }, model));
        }
Exemplo n.º 2
0
 private void MapModelToEntity(BeingModel model, Being entity)
 {
     entity.Id     = model.Id;
     entity.UserId = model.UserId;
     entity.Name   = model.Name;
     entity.Icon   = model.Icon;
     entity.Text   = model.Text;
 }
Exemplo n.º 3
0
 private void MapEntityToModel(Being entity, BeingModel model)
 {
     model.Id     = entity.Id;
     model.UserId = entity.UserId;
     model.Name   = entity.Name;
     model.Icon   = entity.Icon;
     model.Text   = entity.Text;
 }
Exemplo n.º 4
0
        public Task <IActionResult> Update(string id, BeingModel model) => RunBeingAsync(id, Permission.Write, async entity =>
        {
            MapModelToEntity(model, entity);

            db.Beings.Update(entity);
            await db.SaveChangesAsync();

            return(NoContent());
        });
Exemplo n.º 5
0
        protected async Task CreateAsync()
        {
            var model = new BeingModel()
            {
                Id   = Guid.NewGuid().ToString(),
                Name = Name
            };

            await Api.CreateBeingAsync(model);

            Navigator.OpenBeingDetail(model.Id);
        }
Exemplo n.º 6
0
        public Task <IActionResult> Get(string id) => RunBeingAsync(id, Permission.Read, async entity =>
        {
            Permission permission = Permission.Write;
            string userId         = HttpContext.User.FindUserId();
            if (entity.UserId != userId)
            {
                if (!await shareStatus.IsBeingSharedForWriteAsync(id, userId))
                {
                    permission = Permission.Read;
                }
            }

            BeingModel model = new BeingModel();
            MapEntityToModel(entity, model);

            AuthorizedModel <BeingModel> result = new AuthorizedModel <BeingModel>(model);
            result.OwnerId        = entity.UserId;
            result.OwnerName      = await userNames.GetUserNameAsync(entity.UserId);
            result.UserPermission = permission;

            return(Ok(result));
        });
Exemplo n.º 7
0
 public Task UpdateBeingAsync(BeingModel model)
 => faultHandler.Wrap(http.PutAsJsonAsync($"beings/{model.Id}", model));
Exemplo n.º 8
0
 public Task <BeingModel> CreateBeingAsync(BeingModel model)
 => faultHandler.Wrap(http.PostAsJsonAsync <BeingModel, BeingModel>($"beings", model));