public ActionResult Create([Bind(Include = "Id,Name,Zip,City,Country,CreateUser")] Company company)
        {
            if (ModelState.IsValid)
            {
                company.CreateUser = User.Identity.GetUserId();
                try
                {
                    noteService.CreateNote(db, CrudOperation.Create, UserManager.FindById(User.Identity.GetUserId()), null, company);

                    db.CompanySet.Add(company);
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View(company));
        }
        public ActionResult Create([Bind(Include = "Id,Forename,Surname,Email,Phone,CompanyId")] Person person)
        {
            if (ModelState.IsValid)
            {
                person.CreateUser = User.Identity.GetUserId();

                noteService.CreateNote(db, CrudOperation.Create, UserManager.FindById(User.Identity.GetUserId()), person, null, null);

                db.PersonSet.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var companyList = GetCompanySelectList();

            ViewBag.CompanyList = companyList;

            return(View(person));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Description,CreateUser,CreateDate,CompanyId,PersonId,TaskId")] Note note)
        {
            if (ModelState.IsValid)
            {
                note.CreateUser = User.Identity.GetUserId();

                db.NoteSet.Add(note);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var companyList = GetCompanySelectList();

            ViewBag.CompanyList = companyList;
            var personList = GetPersonSelectList();

            ViewBag.PersonList = personList;

            return(View(note));
        }
Example #4
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,Date,CompanyId,PersonId")] Task task)
        {
            if (ModelState.IsValid)
            {
                task.CreateUser = User.Identity.GetUserId();

                noteService.CreateNote(db, CrudOperation.Create, UserManager.FindById(User.Identity.GetUserId()), null, null, task);

                db.TaskSet.Add(task);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var companyList = GetCompanySelectList();

            ViewBag.CompanyList = companyList;
            var personList = GetPersonSelectList();

            ViewBag.PersonList = personList;

            return(View(task));
        }