Esempio n. 1
0
        public async Task <IActionResult> DefaultMapViewSave([FromBody] MapView value)
        {
            DefaultMapView newDefaultMapView;

            try
            {
                newDefaultMapView             = new DefaultMapView();
                newDefaultMapView.UserName    = this.User.Identity.Name;
                newDefaultMapView.Application = value.Application;
                newDefaultMapView.MapViewId   = value.Id;

                DefaultMapView existingDefaultMapView = await GetDefaultMapView(newDefaultMapView);

                if (null == existingDefaultMapView)
                {
                    await _camnContext.DefaultMapViews.AddAsync(newDefaultMapView);

                    newDefaultMapView.Timestamp = DateTime.Now;
                }
                else
                {
                    existingDefaultMapView.MapViewId = value.Id;
                    existingDefaultMapView.Timestamp = DateTime.Now;
                }
                await _camnContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError, e));
            }

            return(Ok(value));
        }
Esempio n. 2
0
 private Task <DefaultMapView> GetDefaultMapView(DefaultMapView value)
 {
     return(_camnContext.DefaultMapViews
            .FirstOrDefaultAsync <DefaultMapView>(
                d => (d.UserName == value.UserName) && (d.Application == value.Application)
                ));
 }
Esempio n. 3
0
        public async Task <IActionResult> DefaultMapView(string application)
        {
            try
            {
                DefaultMapView value = new DefaultMapView();
                value.UserName    = this.User.Identity.Name;
                value.Application = application;
                DefaultMapView defaultMapView = await GetDefaultMapView(value);

                MapView mapView = null;
                if (null != defaultMapView)
                {
                    mapView    = new MapView();
                    mapView.Id = defaultMapView.MapViewId;
                }
                return(Ok(mapView)); // null -> 204 No Content
            }
            catch (Exception e)
            {
                return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError, e));
            }
        }