예제 #1
0
        public ActionResult Create(LeavedViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Types          = new SelectList(Enum.GetValues(typeof(SerialType)).OfType <SerialType>().Where(x => x != SerialType.ADM));
                ViewBag.ShowValidation = true;
                ViewBag.Faculties      = new SelectList(ctx.Faculties, "FacultyId", "FacultyName", model.FacultyId);
                ViewBag.Courses        = new SelectList(ctx.Courses, "CourseId", "CourseName", model.CourseId);
                return(View(model));
            }

            var leaved = new Leaved()
            {
                FirstName  = model.FirstName,
                LastName   = model.LastName,
                FacultyId  = model.FacultyId,
                CourseId   = model.CourseId,
                LeavedDate = model.LeavedDate,
                Serial1    = model.Serial1,
                Serial2    = model.Serial2,
                SerialType = model.SerialType,
                Causes     = model.Causes
            };

            ctx.Leaves.Add(leaved);
            ctx.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public async Task OpenAsync(string userName, CancellationToken cancellationToken)
        {
            _cookieContainer   = new CookieContainer();
            _httpClientHandler = new HttpClientHandler {
                CookieContainer = _cookieContainer
            };

            _progressMessageHandler = new ProgressMessageHandler(_httpClientHandler);
            _progressMessageHandler.HttpSendProgress += MessageHandler_HttpSendProgress;

            _client = new HttpClient(_progressMessageHandler)
            {
                Timeout = TimeSpan.FromMinutes(PackageUploadTimelimitInMinutes)
            };
            _client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");

            var token = await AuthenticateUserAsync(userName, "", cancellationToken);

            _login = userName;

            _connection = new HubConnectionBuilder()
                          .WithUrl($"{ServerAddress}/sionline?token={token}", options =>
            {
                options.AccessTokenProvider = () => Task.FromResult(Convert.ToBase64String(Encoding.UTF8.GetBytes(_login)));
            })
                          .WithAutomaticReconnect()
                          .AddMessagePackProtocol()
                          .Build();

            _connection.Reconnecting += async e =>
            {
                if (Reconnecting != null)
                {
                    await Reconnecting(e);
                }
            };

            _connection.Reconnected += async s =>
            {
                if (Reconnected != null)
                {
                    await Reconnected(s);
                }
            };

            _connection.Closed += OnConnectionClosed;

            _connection.HandshakeTimeout = TimeSpan.FromMinutes(1);

            _connection.On <string, string>("Say", (user, text) => OnUI(() => Receieve?.Invoke(user, text)));
            _connection.On <SI.GameServer.Contract.GameInfo>("GameCreated", (gameInfo) => OnUI(() => GameCreated?.Invoke(ToSICoreGame(gameInfo))));
            _connection.On <int>("GameDeleted", (gameId) => OnUI(() => GameDeleted?.Invoke(gameId)));
            _connection.On <SI.GameServer.Contract.GameInfo>("GameChanged", (gameInfo) => OnUI(() => GameChanged?.Invoke(ToSICoreGame(gameInfo))));
            _connection.On <string>("Joined", (user) => OnUI(() => Joined?.Invoke(user)));
            _connection.On <string>("Leaved", (user) => OnUI(() => Leaved?.Invoke(user)));

            await _connection.StartAsync(cancellationToken);
        }
예제 #3
0
 public LeavedViewModel(Leaved leaved)
 {
     LeavedId       = leaved.LeavedId;
     Serial1        = leaved.Serial1;
     Serial2        = leaved.Serial2;
     SerialType     = leaved.SerialType;
     FirstName      = leaved.FirstName;
     LastName       = leaved.LastName;
     FacultyId      = leaved.FacultyId;
     CourseId       = leaved.CourseId;
     LeavedDate     = leaved.LeavedDate;
     Causes         = leaved.Causes;
     CurrentFaculty = leaved.Faculty.FacultyName;
     CurrentCourse  = leaved.Course.CourseName;
     IndexTable     = new TableViewModel();
 }
예제 #4
0
 /// <inheritdoc cref="OnLeaved"/>
 public void OnLeaved(object sender, WebSocketIoEventArgs args)
 {
     Leaved?.Invoke(sender, args);
 }