Exemplo n.º 1
0
        public IActionResult Create(Person person)
        {
            _context.People.Add(person);
            _context.SaveChanges();

            return(CreatedAtRoute("Get Person", new { id = person.ID }, person));
        }
Exemplo n.º 2
0
        public IActionResult Create(PensionCompany company)
        {
            _context.PensionCompanies.Add(company);
            _context.SaveChanges();

            return(CreatedAtRoute("GetPensionCompany", new { id = company.Id }, company));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "AlbumsID,Title,ArtistID,ReviewID")] Albums albums)
        {
            if (ModelState.IsValid)
            {
                db.Albums.Add(albums);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ArtistID = new SelectList(db.Artists, "ArtistID", "Name", albums.ArtistID);
            return(View(albums));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "id,age,name")] HelloWorld helloWorld)
        {
            if (ModelState.IsValid)
            {
                db.HelloWorlds.Add(helloWorld);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }



            return(View(helloWorld));
        }
Exemplo n.º 5
0
        public IActionResult SaveNewNote([FromBody] StickyNote note)
        {
            try
            {
                DateTime now = DateTime.Now;
                note.CreationDate = now;
                note.UpdatedDate  = now;
                note.Origin       = "Web app";
                _context.StickyNote.Add(note);

                _context.SaveChanges();
            }
            catch (Exception e)
            {
                return(StatusCode(500, e));
            }

            return(Ok(note.Id));
        }
Exemplo n.º 6
0
        public HelloWorldController(HelloWorldContext context)
        {
            _context = context;

            if (_context.HelloWorldItems.Count() == 0)
            {
                // Create a new TodoItem if collection is empty,
                // which means you can't delete all TodoItems.
                _context.HelloWorldItems.Add(new HelloWorldItem());
                _context.SaveChanges();
            }
        }
Exemplo n.º 7
0
        public IActionResult Create(GradesModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _context.Add(model);
            _context.SaveChanges();

            return(View("Details", model));
        }
Exemplo n.º 8
0
        public HelloWorldController(HelloWorldContext context)
        {
            _context = context;

            if (_context.HelloWorldItems.Count() == 0)
            {
                _context.HelloWorldItems.Add(new HelloWorldItem {
                    Name = "Item1"
                });
                _context.SaveChanges();
            }
        }
        public IActionResult Create(Student model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //Save the Data
            _context.Add(model);    //Adding the data to the context
            _context.SaveChanges(); //Saving the data to the table
            return(View("Details", model));
        }
Exemplo n.º 10
0
        //Create
        public Person Create(Person person, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new Exception("Password is required");
            }

            if (_context.People.Any(x => x.Username == person.Username))
            {
                throw new Exception("Username \"" + person.Username + "\" is already taken");
            }

            //Hashing of the password to be saved
            byte[] pwdHash, pwdSalt;
            CreatePasswordHash(password, out pwdHash, out pwdSalt);

            person.PasswordHash = pwdHash;
            person.PasswordSalt = pwdSalt;

            _context.People.Add(person);
            _context.SaveChanges();

            return(person);
        }
Exemplo n.º 11
0
        static public bool AjouterEmploye(Employe employe)
        {
            try
            {
                using (var db = new HelloWorldContext())
                {
                    db.Employes.Add(employe);
                    var count = db.SaveChanges();
                }
            }
            catch (System.Exception e)
            {
                throw e;
            }

            return(true);
        }
Exemplo n.º 12
0
        public HelloWorldController(HelloWorldContext context)
        {
            _context = context;

            if (_context.PensionCompanies.Count() == 0)
            {
                // Create a new PensionCompany if collection is empty,
                // which means you can't delete all PensionCompanies.
                _context.PensionCompanies.Add(new PensionCompany {
                    Name = "PlatinPension"
                });
                _context.PensionCompanies.Add(new PensionCompany {
                    Name = "BedreEndIngen Pension"
                });
                _context.SaveChanges();
            }
        }
        public IActionResult Create(StudentViewModel viewModel)
        {
            Student model = new Student();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //Populating our model
            model.Enrolled        = viewModel.student.Enrolled;
            model.StudentName     = viewModel.student.StudentName;
            model.StudentGenderId = viewModel.student.StudentGenderId;


            //Save the data
            _context.Add(model);    //Adding the data to the context
            _context.SaveChanges(); //Saving the data to the table

            return(View("Details", model));
        }
        public IActionResult Todo([FromForm] SlackSlashCommandPayload data)
        {
            List <string> pLevels = new List <string> {
                "Low", "Med", "High"
            };
            int        pLevelEndIndex = -1;
            string     title          = "";
            string     pLevel         = "";
            StickyNote note           = null;

            try
            {
                string text = data.text;
                if (!String.IsNullOrEmpty(text))
                {
                    text           = text.Trim();
                    pLevelEndIndex = text.IndexOf(' ');
                    if (pLevelEndIndex < 1)
                    {
                        throw new Exception("Invalid format.");
                    }
                    pLevel = text.Substring(0, pLevelEndIndex);
                    title  = text.Substring(pLevelEndIndex + 1, text.Length - 1 - pLevelEndIndex);
                    bool pLevelExists = pLevels.Any(p => p.ToLower().Equals(pLevel.ToLower()));
                    if (!pLevelExists)
                    {
                        throw new Exception("Invalid priority level.");
                    }
                }

                DateTime now = DateTime.Now;
                note = new StickyNote
                {
                    PriorityLevel = pLevel.ToUpper().Substring(0, 1) + pLevel.ToLower().Substring(1),
                    Title         = title,
                    DueDate       = now,
                    CreationDate  = now,
                    UpdatedDate   = now,
                    Origin        = "Slack API"
                };
                _context.StickyNote.Add(note);
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                string msg = e.Message;
                return(Ok(new { Text = $"Whoops! That did not go well. {msg}" }));
            }

            var attachment = new SlackAttachment
            {
                Color       = "good",
                Pretext     = $"Todo list created.",
                Title       = $"Title: {note.Title} \n note_id: {note.Id}",
                Footer      = "HelloWorldApp",
                Footer_icon = "https://ca.slack-edge.com/TCF30M1JQ-UCENPSZC1-g64840305598-48"
            };
            var attachments = new List <object> {
                attachment
            };
            var message = new { attachments };

            //var result = new { Text = $"Todo list created. note_id = {note.Id}" };

            return(Ok(message));
        }