コード例 #1
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(/*[Bind(Include = "Id,StartLocation,EndLocation,StartDate,EndDate")]*/ TravelPlanModel travelPlan)
        {
            bool success = false;

            if (ModelState.IsValid)
            {
                try
                {
                    Carpool         car       = _carpoolRepository.FindById(travelPlan.CarId);
                    List <Employee> employees = _employeeRepository.FindByIds(travelPlan.EmployeeIds).ToList();
                    if (travelPlan.HasDriver && car.NumberOfSeats >= travelPlan.EmployeeIds.Count)
                    {
                        TravelPlan result = new TravelPlan()
                        {
                            StartLocation = travelPlan.StartLocation,
                            EndLocation   = travelPlan.EndLocation,
                            StartDate     = travelPlan.StartDate,
                            EndDate       = travelPlan.EndDate,
                            CarId         = travelPlan.CarId,
                            Car           = car
                        };
                        result.EmployeeTravelPlans = new List <EmployeeTravelPlan>();
                        foreach (var el in employees)
                        {
                            result.EmployeeTravelPlans.Add(new EmployeeTravelPlan()
                            {
                                Employee   = el,
                                EmployeeId = el.Id,
                                TravelPlan = result
                            });
                        }
                        _travelPlanRepository.Add(result);
                        success = true;
                        return(Json(new{ success }));
                    }
                    else
                    {
                        return(Json(new { success }));
                    }
                }
                catch (Exception exe)
                {
                    ModelState.AddModelError("", exe.Message);
                }
            }

            return(Json(new { success }));
        }
コード例 #2
0
 public void Add(TravelPlan travelPlan)
 {
     _travelPlanRepository.Add(travelPlan);
 }