Пример #1
0
        public JsonResult CreateRoom(string ownerName, string roomName, string partnerEmail = null)
        {
            if (ownerName.IsEmpty() || roomName.IsEmpty()) return Json(false);

            back:
            string token = RandomNumbers.GetRandomNumbers();
            if (_db.Rooms.Any(r => r.Token == token)) goto back;

            back2:
            string ownerToken = RandomNumbers.GetRandomNumbers();
            if (_db.Rooms.Any(r => r.OwnerToken == ownerToken)) goto back2;

            var room = new Room
            {
                Token = token,
                Name = roomName.GetValidatedString(),
                OwnerName = ownerName.GetValidatedString(),
                OwnerToken = ownerToken,
                LastUpdated = DateTime.Now,
                SharedWith = partnerEmail.IsEmpty() ? "Public" : partnerEmail,
                Status = Status.Available
            };

            _db.Rooms.InsertOnSubmit(room);
            _db.SubmitChanges();

            return Json(new
            {
                roomToken = room.Token,
                ownerToken = room.OwnerToken
            });
        }
 partial void UpdateRoom(Room instance);
 partial void DeleteRoom(Room instance);
 partial void InsertRoom(Room instance);