Пример #1
0
 public async Task <IActionResult> CreateContractAsync([FromBody] Contracts contract)
 {
     if (contract == null)
     {
         return(BadRequest(""));
     }
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         var entry = _context.Add(new Contracts());
         entry.CurrentValues.SetValues(contract);
         await _context.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         var logdetails = new EventLog()
         {
             ContractId  = contract.ContractId,
             LogMessage  = ex.Message,
             VersionUser = "******",
             VersionDate = DateTime.Now
         };
         var errorlog = _context.Add(new EventLog());
         errorlog.CurrentValues.SetValues(logdetails);
         await _context.SaveChangesAsync();
     }
     return(CreatedAtRoute("GetContract", contract));
 }
Пример #2
0
        public async Task <IActionResult> Create([Bind("PostId,Author,Content,Date")] Comments comments)
        {
            comments.Author = comments.Author == null ? "Anon" : comments.Author;
            comments.Date   = DateTime.Now;
            if (CommentsExists(comments.Id))
            {
                var z = _context.Comments.Select((x) => x.Id).OrderByDescending((y) => y).ToList();
                comments.Id = z[0] + 1;
            }
            _context.Add(comments);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult GetAllContracts()
        {
            var item = _context.Contracts.Select(t => t.Status == "Approved");

            try
            {
                if (item == null)
                {
                    return(NotFound());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                var logdetails = new EventLog()
                {
                    ContractId  = 0,
                    LogMessage  = ex.Message,
                    VersionUser = "******",
                    VersionDate = DateTime.Now
                };
                var errorlog = _context.Add(new EventLog());
                errorlog.CurrentValues.SetValues(logdetails);
                _context.SaveChangesAsync();
            }
            return(new ObjectResult(item));
        }
Пример #4
0
 public void Create()
 {
     using (masterContext con = new masterContext()){
         Games game = new Games();
         System.Console.Write("Enter name of game: ");
         game.Name = Console.ReadLine();
         System.Console.Write("Enter amount of players: ");
         game.Players = long.Parse(Console.ReadLine());
         System.Console.Write("Enter mark of this game: ");
         game.Mark = double.Parse(Console.ReadLine());
         con.Add(game);
         if (con.SaveChanges() > 0)
         {
             Console.ForegroundColor = ConsoleColor.Green;
             System.Console.WriteLine($"{game.Name} was successfully added");
             Console.ForegroundColor = ConsoleColor.White;
         }
         else
         {
             Console.ForegroundColor = ConsoleColor.Red;
             System.Console.WriteLine("Error");
             Console.ForegroundColor = ConsoleColor.White;
         }
     }
 }
Пример #5
0
        public async Task <IActionResult> Create([Bind("IdStudy,Name")] Studies studies)
        {
            if (ModelState.IsValid)
            {
                _context.Add(studies);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(studies));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("Enum,Fname,Mname,Lname,Hours,Email")] Models.Entities.Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("UserId,Useremail,UserPassword,UserType,UserStatus")] Gauser gauser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gauser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gauser));
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("Semester,IdStudy,StartDate,IdEnrollment")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdStudy"] = new SelectList(_context.Studies, "IdStudy", "Name", enrollment.IdStudy);
            return(View(enrollment));
        }
Пример #9
0
 static void Main(string[] args)
 {
     using (masterContext db = new masterContext())
     {
         Item i = new Item()
         {
             ItemName = "afhhbcd", Itemprice = 100
         };
         db.Add(i);
         db.SaveChanges();
     }
 }
Пример #10
0
        public async Task <IActionResult> Create([Bind("BlogUserName,BlogUserPassword,BlogUserAge")] Users users)
        {
            if (ModelState.IsValid)
            {
                users.BlogIsAdmin = false;

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

                return(await Login(users));
            }
            return(View(users));
        }
Пример #11
0
        public async Task <IActionResult> Create([Bind("FolderNum,ApplicationDate,Enum,ConcentrationId,JobId")] Application application)
        {
            if (ModelState.IsValid)
            {
                _context.Add(application);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ConcentrationId"] = new SelectList(_context.Concentration, "ConcentrationId", "ConcentrationId", application.ConcentrationId);
            ViewData["Enum"]            = new SelectList(_context.Student, "Enum", "Enum", application.Enum);
            ViewData["JobId"]           = new SelectList(_context.Job, "JobId", "JobId", application.JobId);
            return(View(application));
        }
Пример #12
0
        public void setNewScore(string winner)
        {
            TblScores oldScore = db.TblScores.FirstOrDefault(x => x.PlayerName == winner);

            if (oldScore != null)
            {
                oldScore.GamesWon++;
                try
                {
                    db.Entry(oldScore).State = EntityState.Modified;

                    _logger.LogInformation("If a player with the same name existed the corresponding record is updated instead of creating a new one");

                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    _logger.LogError("Exception happened:" + ex.Message, ex);
                    throw;
                }
            }
            else
            {
                TblScores newScore = new TblScores();
                newScore.PlayerName = winner;
                newScore.GamesWon   = 1;
                try
                {
                    db.Add(newScore);
                    db.SaveChanges();
                    _logger.LogInformation("if the player name didn't existed the score is a new record.");
                }
                catch (Exception ex)
                {
                    _logger.LogError("Exception happened:" + ex.Message, ex);
                    throw;
                }
            }
            try
            {
                db.Database.ExecuteSqlCommand("TRUNCATE TABLE [tblrounds]");
                _logger.LogInformation("Table rounds truncated to start a new game");
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception happened:" + ex.Message, ex);
                throw;
            }
        }
Пример #13
0
        public async Task <IActionResult> Create([Bind("IndexNumber,FirstName,LastName,BirthDate,IdEnrollment")]
                                                 Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

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

            ViewData["IdEnrollment"] =
                new SelectList(_context.Enrollment, "IdEnrollment", "IdEnrollment", student.IdEnrollment);
            return(View(student));
        }
Пример #14
0
        public async Task <IActionResult> Create([Bind("Title,Date,Content")] Posts posts)
        {
            int z = !_context.Posts.Any() ? 1 : _context.Posts.Max(x => x.Id);

            posts.Id = z + 1;

            if (!HttpContext.Session.TryGetValue("UserName", out var userName))
            {
                return(RedirectToAction("Login", "Users"));
            }

            posts.Author = System.Text.Encoding.UTF8.GetString(userName);
            _context.Add(posts);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Пример #15
0
        public int StartNewRound(TblRounds round)
        {
            try
            {
                round.FirstPlayerMove  = "";
                round.SecondPlayerMove = "";
                round.Winner           = "";
                db.Add(round);
                db.SaveChanges();

                _logger.LogInformation("New Round create with default values.");
                return(round.RoundId);
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception happened:" + ex.Message, ex);
                throw;
            }
        }
Пример #16
0
        public async Task <IActionResult> Create([Bind("Title,Time,Long,Lat")] Events events)
        {
            int z = !_context.Events.Any() ? 1 : _context.Events.Max(x => x.Id);

            events.Id = z + 1;

            if (!HttpContext.Session.TryGetValue("UserName", out var userName))
            {
                return(RedirectToAction("Users", "Login"));
            }
            events.Author = System.Text.Encoding.UTF8.GetString(userName);
            if (ModelState.IsValid)
            {
                _context.Add(events);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(events));
        }
Пример #17
0
        public Form Add(Form newForm)
        {
            db.Add(newForm);

            return(newForm);
        }