Пример #1
0
        public ActionResult Add(ActivitiesViewModel model)
        {
            string errorMessage = "Unable to add the activity to the package.";
            string successMessage = "The activity has been added to your package.";

            if (ModelState.IsValid)
            {
                try
                {
                    // Get co-ordianates of address
                    IGeolocationService geolocationService = UtilityFactory.GetGeolocationService();
                    Location location = geolocationService.GetCoordinates(
                        String.Format("{0}, {1}, {2}", model.Address, model.PackageCity, model.PackageState.ToString()));

                    Activity activity = new Activity()
                    {
                        Name = model.ActivityName,
                        Description = model.Description,
                        Address = model.Address,
                        Status = PackageStatusEnum.Available,
                        PackageId = model.PackageId,
                        Latitude = location.Latitude,
                        Longitude = location.Longitude
                    };

                    ResultEnum result = activityService.AddActivity(activity);

                    if (result == ResultEnum.Success)
                    {
                        model.SuccessMessage = successMessage;
                    }
                    else
                    {
                        model.ErrorMessage = errorMessage;
                    }

                    return View(model);
                }
                catch
                {
                    model.ErrorMessage = errorMessage;
                }
            }

            return View(model);
        }
Пример #2
0
        public ActionResult Add(int PackageId)
        {
            ActivitiesViewModel model = new ActivitiesViewModel();

            Result<Package> result = new Result<Package>();
            result = packageService.GetPackageById(PackageId);

            if (result.Status == ResultEnum.Success &&
                WebSecurity.CurrentUserId == result.Data.ApplicationUserId &&
                result.Data.Activities.Count < MvcApplication.MAX_ACTIVITIES)
            {
                model.PackageId = result.Data.PackageId;
                model.PackageName = result.Data.Name;
                model.PackageCity = result.Data.City;
                model.PackageState = result.Data.State;
                model.ActivityNumber = result.Data.Activities.Count + 1;
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }

            return View(model);
        }
Пример #3
0
        public ActionResult Edit(int? ActivityId, int? PackageId)
        {
            if (ActivityId == null || PackageId == null)
            {
                return RedirectToAction("Index", "Home");
            }

            int activityId = ActivityId.GetValueOrDefault();
            int packageId = PackageId.GetValueOrDefault();

            ActivitiesViewModel model = new ActivitiesViewModel();

            // Get name of package
            Result<Package> packageResult = new Result<Package>();
            packageResult = packageService.GetPackageById(packageId);

            if (packageResult.Status == ResultEnum.Success &&
                WebSecurity.CurrentUserId == packageResult.Data.ApplicationUserId &&
                packageResult.Data.Status == PackageStatusEnum.Available)
            {
                model.PackageId = packageId;
                model.PackageName = packageResult.Data.Name;
                model.PackageCity = packageResult.Data.City;
                model.PackageState = packageResult.Data.State;
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }

            // Get activity details
            Result<Activity> activityResult = new Result<Activity>();
            activityResult = activityService.GetActivityById(activityId);

            if (activityResult.Status == ResultEnum.Success && activityResult.Data.Status == PackageStatusEnum.Available)
            {
                model.ActivityName = activityResult.Data.Name;
                model.Address = activityResult.Data.Address;
                model.Description = activityResult.Data.Description;
                model.ActivityId = activityResult.Data.ActivityId;
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }

            return View(model);
        }