public IActionResult Create(RoomViewModel roomViewModel)
        {
            if (ModelState.IsValid)
            {
                var roomDomain = mapper.Map <Room>(roomViewModel);
                roomApp.Add(roomDomain);

                return(RedirectToAction("Index"));
            }
            return(View(roomViewModel));
        }
예제 #2
0
        public ActionResult Create(RoomViewModel roomViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            roomViewModel = _roomAppService.Add(roomViewModel);
            if (roomViewModel.ValidationResult.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            AddErrorIntoModelState(roomViewModel.ValidationResult);
            return(View(roomViewModel));
        }
예제 #3
0
        public IActionResult Create([FromBody] RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var room = _mapper.Map <Room>(registerViewModel);

                    _roomAppService.Add(room);
                    return(StatusCode(200));
                }
                catch (Exception e)
                {
                    return(StatusCode(400, e.Message));
                }
            }
            else
            {
                return(StatusCode(400));
            }
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync(int id, string position, int mapId)
        {
            ErrorMessage = "";
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            ErrorMessage = "";
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var result = await _romAppService.Add(Room, mapId, id, position);

            if (!result.IsSuccess)
            {
                ErrorMessage = result.Message;
                return(Page());
            }
            else
            {
                return(RedirectToPage("/Room/Index", new { mapId = mapId }));
            }

            /*
             * try
             * {
             *  var map = await _db.Maps.FindAsync(mapId);
             *  if (map == null)
             *  {
             *      return RedirectToPage("/Map/Index");
             *  }
             *
             *
             *  var room = _mapper.Map<RoomEntity>(Room);
             *  room.MapId = mapId;
             *  await _db.Rooms.AddAsync(room);
             *
             *
             *  if (id > 0)
             *  {
             *      var oldRoom = await _db.Rooms.FindAsync(id);
             *      if (oldRoom != null && oldRoom.MapId == mapId)
             *      {
             *          switch (position)
             *          {
             *              case "west":
             *                  if (oldRoom.East == 0)
             *                  {
             *                      oldRoom.East = room.Id;
             *                      oldRoom.EastName = room.Name;
             *
             *                      room.West = oldRoom.Id;
             *                      room.WestName = oldRoom.Name;
             *                  }
             *                  break;
             *
             *              case "east":
             *                  if (oldRoom.West == 0)
             *                  {
             *                      oldRoom.West = room.Id;
             *                      oldRoom.WestName = room.Name;
             *
             *
             *                      room.East = oldRoom.Id;
             *                      room.EastName = oldRoom.Name;
             *                  }
             *                  break;
             *
             *              case "south":
             *                  if (oldRoom.South == 0)
             *                  {
             *                      oldRoom.South = room.Id;
             *                      oldRoom.SouthName = room.Name;
             *
             *                      room.North = oldRoom.Id;
             *                      room.NorthName = oldRoom.Name;
             *                  }
             *                  break;
             *
             *              case "north":
             *                  if (oldRoom.North == 0)
             *                  {
             *                      oldRoom.North = room.Id;
             *                      oldRoom.NorthName = room.Name;
             *
             *                      room.South = oldRoom.Id;
             *                      room.SouthName = oldRoom.Name;
             *                  }
             *                  break;
             *
             *          }
             *      }
             *  }
             *
             *  await _db.SaveChangesAsync();
             *
             *
             *  await AddSuccess(new OperatorLog
             *  {
             *      Type = OperatorLogType.添加房间,
             *      Content = JsonConvert.SerializeObject(Room)
             *  });
             * }
             * catch (Exception ex)
             * {
             *  ErrorMessage = ex.Message;
             *  await AddError(new OperatorLog
             *  {
             *      Type = OperatorLogType.添加房间,
             *      Content = $"Data={JsonConvert.SerializeObject(Room)},ErrorMessage={ErrorMessage}"
             *  });
             *  return Page();
             * }
             *
             * return Redirect(UrlReferer);
             */
        }