示例#1
0
 public async Task Create(NewAnchorModel model, int creatorId)
 {
     _validation.Validate(model);
     _context.Anchors.Add(model.ToEntity(creatorId));
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateException ex)
     {
         throw new Exception(ex.InnerException.Message);
     }
 }
示例#2
0
 /// <summary>
 /// <para>Converts model data for an Anchor into an entity for the database.</para>
 /// </summary>
 /// <param name="anchorModel"></param>
 /// <param name="creatorId"></param>
 /// <returns></returns>
 public static Anchor ToEntity(this NewAnchorModel anchorModel, int creatorId)
 {
     return(new Anchor
     {
         Id = anchorModel.Id,
         Model = anchorModel.Model,
         Location = new Point(anchorModel.Longitude, anchorModel.Latitude)
         {
             SRID = 4326
         },
         CreatedBy = creatorId,
         CreatedAt = DateTime.UtcNow,
         LikedBy = null
     });
 }
示例#3
0
        public async Task <AnchorViewModel> CreateAndGet(NewAnchorModel model, int creatorId)
        {
            await Create(model, creatorId);

            return(GetById(model.Id));
        }
示例#4
0
        public async Task CreateAnchor(NewAnchorModel anchor)
        {
            var newAnchor = await _anchorService.CreateAndGet(anchor, CurrentClient.UserId);

            Dispatch(newAnchor.Location, c => c.NewNearbyAnchor(newAnchor));
        }