Пример #1
0
        public async Task<HttpResponseMessage> Update(RouteViewModel route)
        {
            Route domainRoute = routeService.Find(route.Id);
            if (domainRoute.Author != userService.GetUser(this.UserId))
            {
                return await StatusCode(HttpStatusCode.Forbidden).ExecuteAsync(new CancellationToken());
            } 
            Route temporaryObject = RouteViewModel.MapToDomain(route);
            domainRoute.Description = route.Description;
            domainRoute.MeetingPlace = route.MeetingPlace;
            domainRoute.Title = route.Title;
            domainRoute.Start = temporaryObject.Start;
            domainRoute.Distance = temporaryObject.Distance;
            domainRoute.MapData = temporaryObject.MapData;

            routeService.Update(domainRoute);
            return await StatusCode(HttpStatusCode.OK).ExecuteAsync(new CancellationToken());
        }
Пример #2
0
 public void Put(RouteViewModel route)
 {
     Route domainRoute = route.MapToDomain();
     domainRoute.Author = userService.GetUser(this.UserId);
     routeService.Add(domainRoute);
 }
Пример #3
0
 public static RouteViewModel MapToViewModel(Route route)
 {
     //yes, it's dirty code. it's temporary
     var subscribers = new List<SubscriberViewModel>();
     foreach (var item in route.Subscribers)
     {
         subscribers.Add(new SubscriberViewModel
         {
             Id = item.Id,
             FirstName = item.FirstName,
             SecondName = item.SecondName
         });
     }
     var author = new SubscriberViewModel
         {
             Id = route.Author.Id,
             FirstName = route.Author.FirstName,
             SecondName = route.Author.SecondName
         };
     RouteViewModel _route = new RouteViewModel
     {
         Id = route.Id,
         Title = route.Title,
         MapData = JsonConvert.SerializeObject(route.MapData),
         Description = route.Description,
         MeetingPlace = route.MeetingPlace,
         Start = route.Start,
         Distance = route.Distance.ToString(),
         Author = JsonConvert.SerializeObject(author),
         Subscribers = JsonConvert.SerializeObject(subscribers),
         IsBanned = route.IsBanned
     };
     return _route;
 }
Пример #4
0
 public static Route MapToDomain(RouteViewModel route)
 {
     Route _route = new Route
     {
         Id = route.Id,
         Title = route.Title,
         MapData = JsonConvert.DeserializeObject<MapData>(route.MapData),
         Description = route.Description,
         MeetingPlace = route.MeetingPlace,
         Start = route.Start,
         Distance = Double.Parse(route.Distance, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo),
         //Author = JsonConvert.DeserializeObject<User>(route.Author),
         //Subscribers = JsonConvert.DeserializeObject<List<User>>(route.Subscribers),
         IsBanned = route.IsBanned
     };
     return _route;
 }
Пример #5
0
 public static RouteViewModel MapToSearchViewModel(RouteData route)
 {
     RouteViewModel _route = new RouteViewModel
     {
         Id = route.Id,
         Title = route.Title,
         Description = route.Description,
         MeetingPlace = route.MeetingPlace,
         Start = route.Start,
         Distance = route.Distance.ToString(),
         IsBanned = route.IsBanned
     };
     return _route;
 }