Пример #1
0
        public async Task <ActionResult> Insert([FromBody] R_Viaje_Viajero relacional)
        {
            if (relacional == null || relacional.Viaje < 1 || relacional.Viajero < 1)
            {
                return(BadRequest());
            }

            try
            {
                R_Viaje_Viajero validacion = _context.Viajes_Viajeros.Where(p => p.Viaje == relacional.Viaje && p.Viajero == relacional.Viajero && p.Eliminado == null).FirstOrDefault();
                if (validacion != null)
                {
                    return(Conflict());
                }

                relacional.Id         = 0;
                relacional.Creado     = DateTime.Now;
                relacional.Modificado = relacional.Creado;
                relacional.Eliminado  = null;

                _context.Add(relacional);
                await _context.SaveChangesAsync();

                return(Created(Request.Path.ToString() + "/" + relacional.Id.ToString(), relacional));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Пример #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            var currentUser = LoginForm.LoggedUser.Id;
            var use         = _context.Users.FirstOrDefault(c => c.Id == currentUser);
            var resultGame  = new Statistic {
                Created = _start, GameType = GameType.NumberFindGame, SuccessCount = _successCount, User = use, WrongCount = _wrongCount
            };

            if (timerLeft > 0)
            {
                timerLeft--;
                Timer.Text = timerLeft.ToString();
            }

            if (timerLeft == 0)
            {
                timer1.Stop();

                MessageBox.Show(Timer.Text = "Успешные ходы : " + _successCount +
                                             "\nНеуспешные : " + _wrongCount);
                _context.Add(resultGame);
                _context.SaveChanges();

                Close();
            }
        }
Пример #3
0
        private void Timer_tick(object sender, EventArgs e)
        {
            if (_timerLeft > 0)
            {
                _timerLeft--;
                Timer.Text = _timerLeft.ToString();
            }

            if (_timerLeft == 0)
            {
                time.Stop();

                var currentUser = LoginForm.LoggedUser.Id;
                var use         = _context.Users.FirstOrDefault(c => c.Id == currentUser);
                var resultGame  = new Statistic
                {
                    Created      = _start,
                    GameType     = GameType.FindEvenAndOddNumbers,
                    SuccessCount = _even,
                    User         = use,
                    WrongCount   = _odd
                };

                _context.Add(resultGame);
                _context.SaveChanges();

                MessageBox.Show(Timer.Text = " Четные : " + _even +
                                             "\n Нечетные : " + _odd);
                Close();
            }
        }
        public async Task UploadTemplate(DefaultContext context, string name, User user, Stream stream, long length, Action <double> callback = null)
        {
            await context.Database.BeginTransactionAsync();

            var hypervisor = await context.Hypervisors.FirstOrDefaultAsync();

            context.Entry(user).State = EntityState.Unchanged;
            var vmTemplate = new VmTemplate
            {
                Name         = name,
                Owner        = user,
                IsCoreRouter = false,
            };

            context.Add(vmTemplate);
            await context.SaveChangesAsync();

            var templateId = await UploadVmTemplate(
                name, stream, length, hypervisor, vmTemplate, callback);

            var primaryHypervisorNode = await ProxmoxManager.GetPrimaryHypervisorNode(hypervisor);

            vmTemplate.HypervisorVmTemplates = new List <HypervisorVmTemplate>
            {
                new HypervisorVmTemplate
                {
                    HypervisorNode = primaryHypervisorNode,
                    TemplateVmId   = templateId
                }
            };
            await context.SaveChangesAsync();

            context.Database.CommitTransaction();
        }
Пример #5
0
        public async Task <ActionResult> Insert([FromBody] Viaje viaje)
        {
            if (viaje == null)
            {
                return(BadRequest());
            }

            try
            {
                Viaje validacion = _context.Viajes.Where(p => p.Codigo == viaje.Codigo && p.Eliminado == null).FirstOrDefault();
                if (validacion != null)
                {
                    return(Conflict());
                }

                viaje.Id         = 0;
                viaje.Creado     = DateTime.Now;
                viaje.Modificado = viaje.Creado;
                viaje.Eliminado  = null;

                _context.Add(viaje);
                await _context.SaveChangesAsync();

                return(Created(Request.Path.ToString() + "/" + viaje.Id.ToString(), viaje));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Пример #6
0
        private void CheckForWinner()
        {
            for (var i = 0; i < tableLayoutPanel1.Controls.Count; i++)
            {
                var label = tableLayoutPanel1.Controls[i] as Label;
                if (label != null && label.ForeColor == label.BackColor)
                {
                    return;
                }
            }
            var currentUser = LoginForm.LoggedUser.Id;

            var use        = _context.Users.FirstOrDefault(c => c.Id == currentUser);
            var resultGame = new Statistic {
                Created = _start, GameType = GameType.CoubeGameLevel2, SuccessCount = _successCount, User = use, WrongCount = _wrongCounter
            };
            var finishText = $"Успешные завершений: {_successCount} :: Неправильные: {_wrongCounter}";

            _context.Add(resultGame);
            _context.SaveChanges();

            MessageBox.Show(finishText);

            Close();
        }
Пример #7
0
        public async Task <ActionResult> Insert([FromBody] Viajero viajero)
        {
            if (viajero == null || string.IsNullOrEmpty(viajero.Cedula) || string.IsNullOrEmpty(viajero.Nombres) || string.IsNullOrEmpty(viajero.Apellidos))
            {
                return(BadRequest());
            }

            try
            {
                Viajero validacion = _context.Viajeros.Where(p => p.Cedula == viajero.Cedula && p.Eliminado == null).FirstOrDefault();
                if (validacion != null)
                {
                    return(Conflict());
                }

                viajero.Id         = 0;
                viajero.Creado     = DateTime.Now;
                viajero.Modificado = viajero.Creado;
                viajero.Eliminado  = null;

                _context.Add(viajero);
                await _context.SaveChangesAsync();

                return(Created(Request.Path.ToString() + "/" + viajero.Id.ToString(), viajero));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Пример #8
0
        private void doneButton_Click(object sender, EventArgs e)
        {
            doneButton.Enabled  = false;
            startButton.Enabled = true;
            timer1.Stop();

            int resultPlus  = A + B;
            int resultMinus = A - B;

            var currentUser = LoginForm.LoggedUser.Id;
            var use         = _context.Users.FirstOrDefault(c => c.Id == currentUser);
            var resultGame  = new Statistic {
                Created = _start, GameType = GameType.MathTImeGame, User = use,
            };

            if (answerPlusBox.Text == resultPlus.ToString() &&
                AnswerMinusBox.Text == resultMinus.ToString())
            {
                timer1.Stop();
                timerLabel.Text     = "Вы выиграли!";
                answerPlusBox.Text  = "";
                AnswerMinusBox.Text = "";


                _context.Add(resultGame);
                _context.SaveChanges();

                Hide();
            }
            else
            {
                timerLabel.Text = "Вы проиграли";
            }
        }
Пример #9
0
        public bool SaveMoreInfo([FromBody] Contact contact)
        {
            using DefaultContext ctx = new DefaultContext();
            ctx.Add(contact);
            ctx.SaveChanges();

            return(true);
        }
        public async Task <IActionResult> Create([Bind("ProjectId,Name,Project_Adress,Uploaded_Date,StudentId,TeacherId")] Project project)
        {
            if (ModelState.IsValid)
            {
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(project));
        }
Пример #11
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Region region)
        {
            if (ModelState.IsValid)
            {
                _context.Add(region);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(region));
        }
        public async Task <IActionResult> Create([Bind("DisciplineId,Title")] Discipline discipline)
        {
            if (ModelState.IsValid)
            {
                _context.Add(discipline);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(discipline));
        }
Пример #13
0
        public async Task <IActionResult> Create([Bind("StudentId,Password,Username,StudentName,Group,Field,Year")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Пример #14
0
        public async Task <IActionResult> Create([Bind("Id,Original,Regional,UserId,RegionId")] Expression expression)
        {
            if (ModelState.IsValid)
            {
                _context.Add(expression);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(expression));
        }
Пример #15
0
        public async Task <IActionResult> Create(BlogModel model)
        {
            if (ModelState.IsValid)
            {
                DB.Add(model);
                await DB.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Пример #16
0
        public async Task <IActionResult> Create([Bind("Id,Title,Content,CreateTime,CreateUser,Status")] BlogModel blogModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blogModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blogModel));
        }
Пример #17
0
        public async Task <IActionResult> Create([Bind("TeacherId,Password,Username,TeacherName,Subject")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teacher));
        }
Пример #18
0
        public async Task <IActionResult> Create([Bind("Id,UserId,ExpressionId")] Vote vote)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vote);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vote));
        }
        public async Task <IActionResult> CreateStagiaire([Bind("MatriculeStagiaire,DateNaissanceStagiaire,IdPersonne,NomPersonne,PrenomPersonne,CivilitePersonne,SexePersonne,AdresseMail,CatPersonne")] Stagiaire stagiaire)
        {
            if (ModelState.IsValid)
            {
                _context.Add(stagiaire);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stagiaire));
        }
        public async Task <IActionResult> Create([Bind("Id,Login,Password,RoleId,RegDate,IsBlocked")] UsersModel usersModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(usersModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(usersModel));
        }
Пример #21
0
        public async Task <IActionResult> Create([Bind("Id,Name,DateDeSortie,Stock,GenreId")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenreId"] = new SelectList(_context.Genres, "Id", "Name", movie.GenreId);
            return(View(movie));
        }
Пример #22
0
        public async Task <IActionResult> Create([Bind("Id,Name,Birthday,IsSubscribedToNewsletter,AdhesionId")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AdhesionId"] = new SelectList(_context.Adhesions, "Id", "Name", customer.AdhesionId);
            return(View(customer));
        }
Пример #23
0
        public async Task <IActionResult> Create([Bind("Id,Text,TourId")] SchedulesModel schedulesModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(schedulesModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TourId"] = new SelectList(_context.Tours, "Id", "Id", schedulesModel.TourId);
            return(View(schedulesModel));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,IsSpecial,IsTour,IsBustour,IsCruise,CategoryId")] FiltersModel filtersModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(filtersModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", filtersModel.CategoryId);
            return(View(filtersModel));
        }
Пример #25
0
        public IActionResult Post(Customer customer)
        {
            try
            {
                _dbContext.Add(customer);
                _dbContext.SaveChanges();
                return CreatedAtRoute(nameof(GetById), new { customer.Id }, null);
            }
            catch (Exception)
            {

                return BadRequest();
            }
        }
Пример #26
0
        public async Task <IActionResult> Create(
            [Bind("Id,Notes,Latitude,Longitude,LocationOverride,WeatherSummary,Date")]
            JournalEntry journalEntry)
        {
            if (ModelState.IsValid)
            {
                _context.Add(journalEntry);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(journalEntry));
        }
Пример #27
0
        public void button1_Click(object sender, EventArgs e)
        {
            var anotherDelayTime = delayTime - (level * 500);

            var timer = new System.Windows.Forms.Timer {
                Enabled = true, Interval = anotherDelayTime <= 2000 ? 2000 : anotherDelayTime
            };

            timer.Tick += (o, a) => { timer.Stop(); label1.Hide(); };

            string text        = textBox1.Text;
            var    currentUser = LoginForm.LoggedUser.Id;
            var    use         = _context.Users.FirstOrDefault(c => c.Id == currentUser);
            var    resultGame  = new Statistic {
                Created = start, GameType = GameType.StringGame, SuccessCount = level, User = use, WrongCount = wrongCounter
            };

            if (start < DateTime.Now)
            {
                var finishText = $"Вы прошли уровень!: {level} :: Неправильне : {wrongCounter}";
                MessageBox.Show(finishText);
                label1.Text      = finishText;
                button1.Enabled  = false;
                textBox1.Enabled = false;
                label1.Show();
                timer.Enabled = false;
                _context.Add(resultGame);
                _context.SaveChanges();

                Close();
            }
            else if ((randomText == text.ToUpper()))
            {
                ++textLength;
                ++level;
                randomText    = RandomString(textLength);
                label1.Text   = randomText;
                textBox1.Text = randomText;
                label1.Show();
            }
            else
            {
                wrongCounter++;
                randomText    = RandomString(textLength);
                label1.Text   = randomText;
                textBox1.Text = randomText;
                label1.Show();
            }
        }
        public async Task <IActionResult> Create([Bind("Title,Image,FilterId")] FilterAllowablesModel filterAllowablesModel, IFormFile imageFile)
        {
            //if (imageFile != null)
            //    filterAllowablesModel.Image = ImageHelper.AddImage(_appEnvironment, imageFile);
            if (ModelState.IsValid)
            {
                _context.Add(filterAllowablesModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { id = filterAllowablesModel.FilterId }));
            }
            ViewData["FilterId"] = new SelectList(_context.Filters, "Id", "Title");
            ViewBag.Filter       = _context.Filters.Find(filterAllowablesModel.FilterId);
            return(View(filterAllowablesModel));
        }
Пример #29
0
        public IActionResult createUser(Usuario user)
        {
            try
            {
                db.Add(user);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                // I'll think about a more meaningful error later
                return(StatusCode(500));
            }

            return(Ok());
        }
Пример #30
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,ShortDescription,Image,UrlRus")] CategoriesModel categoriesModel, IFormFile imageFile)
        {
            if (imageFile != null)
            {
                categoriesModel.Image = ImageHelper.AddImage(_appEnvironment, imageFile);
            }
            if (ModelState.IsValid)
            {
                _context.Add(categoriesModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoriesModel));
        }