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)); }
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; }
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; }
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()); });
protected async Task CreateAsync() { var model = new BeingModel() { Id = Guid.NewGuid().ToString(), Name = Name }; await Api.CreateBeingAsync(model); Navigator.OpenBeingDetail(model.Id); }
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)); });
public Task UpdateBeingAsync(BeingModel model) => faultHandler.Wrap(http.PutAsJsonAsync($"beings/{model.Id}", model));
public Task <BeingModel> CreateBeingAsync(BeingModel model) => faultHandler.Wrap(http.PostAsJsonAsync <BeingModel, BeingModel>($"beings", model));