Ejemplo n.º 1
0
 public IHttpActionResult Put(int id, [FromBody] MapObjectViewModel mapObject)
 {
     try
     {
         if (id == mapObject.Id)
         {
             // This is for confirmation by the administrator.
             // From the confirmation page comes the mapObject with the fields Id and Status.
             // We find the object in the database, load it, change its status and save it.
             if (mapObject.Status == Status.Approved)
             {
                 mapObject.TimeStamp = DateTime.Now;
                 mapObject           = Mapper
                                       .Map <MapObjectDTO, MapObjectViewModel>(mapObjectService.GetMapObject(id));
                 mapObject.Status = Status.Approved;
             }
             var approvedMapObject = Mapper
                                     .Map <MapObjectViewModel, MapObjectDTO>(mapObject);
             mapObjectService.UpdateMapObject(approvedMapObject);
             return(Ok());
         }
         return(BadRequest());
     }
     catch
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 2
0
 public string Resolve(MapObjectDTO source, MapObjectViewModel destination, List <TagDTO> sourceMember, string destMember, ResolutionContext context)
 {
     destination.Tags = "";
     foreach (var tag in source.Tags)
     {
         destination.Tags += tag.TagName + ";";
     }
     return(destination.Tags);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Method for adding an object to the database.
 /// </summary>
 /// <param name="mapObject">Adding object.</param>
 /// <returns>In case of successful addition, returns OkResult().
 /// If an exception occurs, then BadRequest().</returns>
 public IHttpActionResult Post([FromBody] MapObjectViewModel mapObject)
 {
     try
     {
         mapObject.TimeStamp = DateTime.Now;
         var addMapObject = Mapper.Map <MapObjectViewModel, MapObjectDTO>(mapObject);
         mapObjectService.AddMapObject(addMapObject);
         return(Ok());
     }
     catch
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 4
0
            public List <TagDTO> Resolve(MapObjectViewModel source, MapObjectDTO destination, string sourceMember, List <TagDTO> destMember, ResolutionContext context)
            {
                destination.Tags = new List <TagDTO>();
                var tags = TagStringHandler.SplitAndTrimTagsString(source.Tags);

                foreach (var tag in tags)
                {
                    destination.Tags.Add(new TagDTO
                    {
                        Id      = 0,
                        TagName = tag
                    });
                }
                return(destination.Tags);
            }
Ejemplo n.º 5
0
 /// <summary>
 /// Method for updating the object in the database.
 /// </summary>
 /// <param name="id">Object's ID.</param>
 /// <param name="mapObject">Updating object.</param>
 /// <returns> If the update is successful, it returns OkResult().
 /// If an exception occurs, then BadRequest.</returns>
 public IHttpActionResult Put(int id, [FromBody] MapObjectViewModel mapObject)
 {
     try
     {
         if (id == mapObject.Id)
         {
             mapObject.TimeStamp = DateTime.Now;
             var updateMapObject = Mapper
                                   .Map <MapObjectViewModel, MapObjectDTO>(mapObject);
             mapObjectService.UpdateMapObject(updateMapObject);
             return(Ok());
         }
         return(BadRequest());
     }
     catch
     {
         return(BadRequest());
     }
 }