예제 #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));
        }
예제 #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;
 }
예제 #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;
 }
예제 #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());
        });
예제 #5
0
        protected async Task CreateAsync()
        {
            var model = new BeingModel()
            {
                Id   = Guid.NewGuid().ToString(),
                Name = Name
            };

            await Api.CreateBeingAsync(model);

            Navigator.OpenBeingDetail(model.Id);
        }
예제 #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));
        });
예제 #7
0
 public Task UpdateBeingAsync(BeingModel model)
 => faultHandler.Wrap(http.PutAsJsonAsync($"beings/{model.Id}", model));
예제 #8
0
 public Task <BeingModel> CreateBeingAsync(BeingModel model)
 => faultHandler.Wrap(http.PostAsJsonAsync <BeingModel, BeingModel>($"beings", model));