Beispiel #1
0
 public Request(User user, Package package, Location origin, Location destination)
 {
     this.Destination = destination;
     this.RequestedUser = user;
     this.Origin = origin;
     this.Package = package;
 }
        public ViewResult Create(CreateRequestResponse requestResponse)
        {
            if (ModelState.IsValid)
            {
                Package package = new Package(requestResponse.PackageDescription, requestResponse.PackageWeight, requestResponse.PackageDescription);
                Location origin = new Location(requestResponse.OriginPlace, null);
                Location destination = new Location(requestResponse.DestinationPlace, new TravelDate(DateTime.Parse(requestResponse.DestinationDate)));
                if (User.Identity.IsAuthenticated)
                {
                    IUserRepository userRepository = UserRepository.Instance;
                    DomainModel.User user = userRepository.LoadUser(User.Identity.Name);
                    DomainModel.Request request = new Request(user, package, origin, destination);
                    DomainModel.RequestRepository.Instance.Save(request);

                    ViewData["Message"] = "Request Submitted Successfully!";
                    ViewData["AllRequests"] = GetAllRequests(User.Identity.Name);
                }
                else
                {
                    ViewData["Message"] = "You need to be registered to view this page!";
                }
            }

            return View(requestResponse);
        }