コード例 #1
0
        public async Task <IActionResult> PutEvent([FromRoute] int id, [FromBody] Event @event)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != @event.Id)
            {
                return(BadRequest());
            }

            _context.Entry(@event).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("CompanyId,CompanyName,Logo,StreetAndNumber,PostalCode,City,Country,PhoneNumber,Email")] CompanyModel companyModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(companyModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(companyModel));
        }
コード例 #3
0
        public async Task <IActionResult> Create(IndustryModel industryModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(industryModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(industryModel));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("DepartmentID,Name,Budget,StartDate,InstructorID,RowVersion")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["InstructorID"] = new SelectList(_context.Instructors, "ID", "FullName", department.InstructorID);
            return(View(department));
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("CourseID,Title,Credits,DepartmentID")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentID"] = new SelectList(_context.Departments, "DepartmentID", "DepartmentID", course.DepartmentID);
            return(View(course));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("EnrollmentID,CourseID,StudentID,Grade")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseID"]  = new SelectList(_context.Courses, "CourseID", "CourseID", enrollment.CourseID);
            ViewData["StudentID"] = new SelectList(_context.Students, "ID", "Discriminator", enrollment.StudentID);
            return(View(enrollment));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("ID,RegistrationNumber,Type,CarBrand,CarModel,CustomerModelID")] VehicleModel vehicleModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicleModel);
                await _context.SaveChangesAsync();

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

            ViewData["CustomerModelID"] = new SelectList(_context.Customers, "ID", "ID", vehicleModel.CustomerModelID);

            return(View(vehicleModel));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("ID,Risk,StartTime,EndTime,VehicleModelID,CustomerModelID")] VehiclePolicyModel vehiclePolicyModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehiclePolicyModel);
                await _context.SaveChangesAsync();

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

            ViewData["VehicleModelID"]  = new SelectList(_context.Vehicles, "ID", "ID", vehiclePolicyModel.VehicleModelID);
            ViewData["CustomerModelID"] = new SelectList(_context.Customers, "ID", "ID", vehiclePolicyModel.CustomerModelID);

            return(View(vehiclePolicyModel));
        }
コード例 #9
0
        public async Task <IActionResult> Create([Bind("WorkHoursId,StartHour,StartMinutes,EndHour,EndMinutes,DayName,AdditionalInfo,Date,Employee")] WorkHoursModel workHours, string id, int departmentId)
        {
            var user = userManager.FindByIdAsync(id);

            workHours.Employee = user.Result;
            workHours.DayName  = workHours.Date.DayOfWeek.ToString();

            if (ModelState.IsValid)
            {
                _context.Add(workHours);
                await _context.SaveChangesAsync();

                return(Redirect($"/Calendar/Display?departmentId={departmentId}"));
            }
            return(View(workHours));
        }
コード例 #10
0
        public async Task <IActionResult> Create(
            [Bind("EnrollmentDate,FirstMidName,LastName")] Student student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(student);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(student));
        }
コード例 #11
0
        public async Task <IActionResult> Create([Bind("FirstMidName,HireDate,LastName,OfficeAssignment")] Instructor instructor, string[] selectedCourses)
        {
            if (selectedCourses != null)
            {
                instructor.CourseAssignments = new List <CourseAssignment>();
                foreach (var course in selectedCourses)
                {
                    var courseToAdd = new CourseAssignment {
                        InstructorID = instructor.ID, CourseID = int.Parse(course)
                    };
                    instructor.CourseAssignments.Add(courseToAdd);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(instructor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateAssignedCourseData(instructor);
            return(View(instructor));
        }
コード例 #12
0
 public async Task AddCustomer(CustomerModel customerModel)
 {
     _context.Add(customerModel);
     await _context.SaveChangesAsync();
 }
コード例 #13
0
 public async Task <bool> Commit()
 {
     return(await _context.SaveChangesAsync() > 0);
 }