Ejemplo n.º 1
0
        public JsonResult PostingTheData([FromBody] TripModelView data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newTrip = Mapper.Map <Trip>(data);
                    Response.StatusCode = (int)HttpStatusCode.Created;

                    newTrip.UserName = User.Identity.Name; // adding the username

                    //save the data(trip) to the database
                    _logger.LogInformation("Attempting to save " + data.Name + " in the database");
                    _repository.Add(newTrip);

                    if (_repository.SaveAll())
                    {
                        _logger.LogInformation("Successfully add the trip " + newTrip.Name + " in to the database");
                        return(Json(Mapper.Map <TripModelView>(newTrip)));
                    }
                }

                // in case if data is not valid then do the following
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                _logger.LogError("Error occur may be due to the model Invalidation, pleae check the log for full trace : " + ModelState);
                return(Json(new { Message = "Invalid data", ErrorProne = ModelState }));
            }catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.ExpectationFailed;
                _logger.LogError("Error occur in the post api/trips service may be mapping, for trace error view the detail: " + ex);
                return(Json(new { Message = "Error occur in the mapping", Error = ex }));
            }
        }
        //public ActionResult Add([FromBody]Country country)
        public ActionResult Add([FromForm] WorldForListDto countryForListDto, WorldParameter WorldParameter)
        {
            /* var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
             *
             * if (currentUserId ==null)
             * {
             *   return Unauthorized();
             * }*/

            _worldRepository.Add(WorldParameter);
            _worldRepository.SaveAll();
            return(Ok(WorldParameter));
        }
Ejemplo n.º 3
0
        public IActionResult CreateWorld([FromBody] World world)
        {
            var auth = Auth as AccountSession;

            if (auth == null)
            {
                return(Unauthorized());
            }

            var acc = auth.GetAccount(HttpContext.RequestServices);

            switch (acc.Type)
            {
            case AccountType.ERROR:
                throw new InvalidOperationException("Invalid account type: " + acc.Guid);

            case AccountType.Standard:
                if (world.Privacy == WorldPrivacy.ERROR)
                {
                    return(BadRequest());
                }
                break;

            case AccountType.Research:
                world.Privacy = WorldPrivacy.InviteOnly;
                break;

            default:
                throw new NotImplementedException();
            }

            world.Status = WorldStatus.Passed;

            world.Account     = acc;
            world.BackupUser  = null;
            world.Application = Application.Default();

            if (world.Description == null)
            {
                world.Description = Description.Default();
            }

            world.PairingSettings = null;

            worlds.Add(world);

            return(Ok(world));
        }