Beispiel #1
0
        public ActionResult Reserve(ReservationModel reserveModel)
        {
            if (reserveModel == null)
            {
                return(HttpNotFound());
            }
            tOferta offer    = reserveModel.Offer;
            int?    clientId = AuthorizeUtil.GetUserId(service, User);

            ViewBag.IsReserved = IsOfferReserved(offer.IDOferty);
            if (clientId == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            try
            {
                if (!service.IsOfferReserved(offer.IDOferty, reserveModel.PersonId, clientId.Value))
                {
                    service.ReserveOffer(offer.IDOferty, reserveModel.PersonId, clientId.Value);
                }
                ViewBag.ReserveMessage = "Offer is reserved";
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Failed to reserve offer: " + ex.Message);
            }
            return(View(reserveModel));
        }
Beispiel #2
0
        public ActionResult Reserve(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tOferta tOferta = service.FindOffer(id.Value);

            if (tOferta == null)
            {
                return(HttpNotFound());
            }
            int?userId = AuthorizeUtil.GetUserId(service, User);

            if (userId == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            tKlient client   = service.GetClientWithPersons(userId.Value);
            int     personId = client.tOsoby.First().IDOsoby;

            ViewBag.IsReserved = IsOfferReserved(id.Value);
            return(View(new ReservationModel {
                Offer = tOferta, ClientWithPersons = client, PersonId = personId
            }));
        }
        protected void ConfirmButton_Click(object sender, EventArgs e)
        {
            int attractionId;

            if (int.TryParse(AttractionId.Value, out attractionId))
            {
                var attraction = service.FindAttraction(attractionId);
                if (attraction != null)
                {
                    if (IsOfferReserved(attraction.IDAtrakcjiUslugi))
                    {
                        int?userId = AuthorizeUtil.GetUserId(service, User);
                        if (userId == null)
                        {
                            Response.Redirect("~/Account/Login");
                        }
                        pnlConfirm.Visible = false;
                        if (!IsAttractionReserved(attractionId))
                        {
                            tKlient client   = service.GetClientWithPersons(userId.Value);
                            int     personId = client.tOsoby.First().IDOsoby;
                            service.ReserveAttraction(attractionId, personId, client.IDKlienta);
                        }
                        Message.Text = "Offer has been reserved.";
                    }
                    else
                    {
                        pnlConfirm.Visible = false;
                        Message.Text       = "Offer related to this attraction has to be reserved first.";
                    }
                }
            }
        }
        protected void ConfirmButton_Click(object sender, EventArgs e)
        {
            int offerId;

            if (int.TryParse(OfferId.Value, out offerId))
            {
                var offer = service.FindOffer(offerId);
                if (offer != null)
                {
                    int?userId = AuthorizeUtil.GetUserId(service, User);
                    if (userId == null)
                    {
                        Response.Redirect("~/Account/Login");
                    }
                    pnlConfirm.Visible = false;
                    if (!IsOfferReserved(offerId))
                    {
                        tKlient client   = service.GetClientWithPersons(userId.Value);
                        int     personId = client.tOsoby.First().IDOsoby;
                        service.ReserveOffer(offerId, personId, client.IDKlienta);
                    }
                    Message.Text = "Offer has been reserved.";
                }
            }
        }
        public ActionResult Reserve(ReservationModel reserveModel)
        {
            if (reserveModel == null)
            {
                return(HttpNotFound());
            }
            tAtrakcjeUslugi attraction = reserveModel.Attraction;
            int?            clientId   = AuthorizeUtil.GetUserId(service, User);

            if (clientId == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            ConfigureViewBag(attraction, clientId);
            try
            {
                if (service.IsOfferReserved(attraction.IDOferty, clientId))
                {
                    if (!service.IsAttractionReserved(attraction.IDAtrakcjiUslugi, reserveModel.PersonId, clientId.Value))
                    {
                        service.ReserveAttraction(attraction.IDAtrakcjiUslugi, reserveModel.PersonId, clientId.Value);
                    }
                    ViewBag.ReserveMessage = "Attraction is reserved";
                }
                else
                {
                    ModelState.AddModelError("", "Offer is not reserved. To reserve attraction reserve offer first.");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Failed to reserve offer: " + ex.Message);
            }
            return(View(reserveModel));
        }
        public ActionResult Reserve(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tAtrakcjeUslugi attraction = service.FindAttraction(id.Value);

            if (attraction == null)
            {
                return(HttpNotFound());
            }
            int?userId = AuthorizeUtil.GetUserId(service, User);

            if (userId == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            tKlient client   = service.GetClientWithPersons(userId.Value);
            int     personId = client.tOsoby.First().IDOsoby;

            ConfigureViewBag(attraction, userId);
            return(View(new ReservationModel {
                Attraction = attraction, ClientWithPersons = client, PersonId = personId
            }));
        }
        public string GetCurrentAccessToken()
        {
            if (githubAccounts == null || githubAccounts.Count == 0)
            {
                githubAccounts = db.GithubAccounts.ToList <GithubAccount>();
            }
            string accessToken = AuthorizeUtil.GetToken(githubAccounts[accountIndex].UserName, githubAccounts[accountIndex].Password);

            return(accessToken);
        }
Beispiel #8
0
        public ActionResult Index()
        {
            int?userId = AuthorizeUtil.GetUserId(service, User);

            if (userId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var history = service.GetOfferHistory(userId.Value);

            return(View(history));
        }
        private bool IsAttractionReserved(int attrId)
        {
            int?userId = AuthorizeUtil.GetUserId(service, User);

            if (userId == null)
            {
                return(false);
            }
            tKlient client = service.GetClientWithPersons(userId.Value);

            return(service.IsAttractionReserved(attrId, client.tOsoby.First().IDOsoby, userId.Value));
        }
 public string GetNextAccessToken()
 {
     if (accountIndex < this.githubAccounts.Count && this.githubAccounts.Count != 1)
     {
         accountIndex++;
         string accessToken = AuthorizeUtil.GetToken(githubAccounts[accountIndex].UserName, githubAccounts[accountIndex].Password);
         return(accessToken);
     }
     else
     {
         githubAccounts = db.GithubAccounts.ToList <GithubAccount>();
         accountIndex   = 0;
         return(this.GetCurrentAccessToken());
     }
 }
        // GET: Attractions
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tAtrakcjeUslugi attraction = service.FindAttraction(id.Value);

            if (attraction == null)
            {
                return(HttpNotFound());
            }
            ConfigureViewBag(attraction, AuthorizeUtil.GetUserId(service, User));
            return(View(attraction));
        }
Beispiel #12
0
        public ActionResult AttractionDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            int?userId = AuthorizeUtil.GetUserId(service, User);

            if (userId == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            var history = service.GetAttractionHistory(userId.Value, id.Value);

            return(View(history));
        }
Beispiel #13
0
 private bool IsOfferReserved(int offerId)
 {
     return(service.IsOfferReserved(offerId, AuthorizeUtil.GetUserId(service, User)));
 }
Beispiel #14
0
        // GET: Offers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tOferta tOferta = service.FindOffer(id.Value);

            if (tOferta == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IsReserved         = IsOfferReserved(id.Value);
            ViewBag.AttractionReserved = new AttractionReserved(service.GetAttractionIdToReservedMap(AuthorizeUtil.GetUserId(service, User)));
            return(View(tOferta));
        }
Beispiel #15
0
        // GET: Offers
        public ActionResult Index()
        {
            int?page = null;
            int value;

            if (int.TryParse(Request.QueryString["page"], out value))
            {
                page = value;
            }
            var tOferta   = service.GetOffers();
            var filtering = new FilteringData(Request.QueryString, ModelState);

            tOferta = filtering.Apply(tOferta).OrderBy(i => i.DataWyjazdu);

            int pageNumber = (page ?? 1);
            IDictionary <int, bool> offerToReservedMap = service.GetOfferIdToReservedMap(AuthorizeUtil.GetUserId(service, User));

            return(View(new OffersViewModel(
                            tOferta.ToPagedList(pageNumber, filtering.ItemsOnPage), filtering, offerToReservedMap)));
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            List <GithubAccount> githubAccounts = GithubAccountsLoader.Load();

            string          githubAddress   = args[0];
            GithubExtractor githubExtractor = new GithubExtractor();

            ExtractRequest extractRequest = new ExtractRequest();

            extractRequest.URL       = githubAddress;
            extractRequest.StartPage = 0;
            extractRequest.PerPage   = 100;

            int accountIndex            = 0;
            HashSet <string> userLogins = new HashSet <string>();

            for (; accountIndex < githubAccounts.Count;)
            {
                extractRequest.Account = githubAccounts[accountIndex];

                string accessToken = AuthorizeUtil.GetToken(extractRequest.Account.UserName, extractRequest.Account.Password);
                extractRequest.AccessToken = accessToken;
                extractRequest.Left        = 5000;
                HashSet <string> user_logins = githubExtractor.ExtractUserLogin(extractRequest);
                if (user_logins.Count == 0)
                {
                    accountIndex++;
                    break;
                }
                foreach (string ul in user_logins)
                {
                    userLogins.Add(ul);
                }
                if (extractRequest.Left > 0)
                {
                    accountIndex++;
                    break;
                }
            }

            List <string> userLoginList = new List <string>();

            foreach (string ul in userLogins)
            {
                userLoginList.Add(ul);
            }


            string exportFile = githubAddress + ".csv";

            exportFile = exportFile.Replace("/", "_");
            exportFile = exportFile.Replace(":", "_");

            if (File.Exists(exportFile))
            {
                File.Move(exportFile, exportFile + "." + Guid.NewGuid());
            }

            extractRequest.StartIndex = 0;

            using (StreamWriter streamWriter = new StreamWriter(exportFile, true, Encoding.Default))
            {
                //write the header line
                StringBuilder sb = new StringBuilder();
                sb.Append("Name").Append(","); //没一个字段后面都加逗号,表示是一列,因为这是第一行    因此也是列标题
                sb.Append("Followers").Append(",");
                sb.Append("Email").Append(",");
                sb.Append("Company").Append(",");
                sb.Append("Location").Append(",");
                streamWriter.WriteLine(sb.ToString());
            }
            // use the List to get the user info instead.
            for (; accountIndex < githubAccounts.Count; accountIndex++)
            {
                extractRequest.Account = githubAccounts[accountIndex];

                string accessToken = AuthorizeUtil.GetToken(extractRequest.Account.UserName, extractRequest.Account.Password);
                extractRequest.AccessToken = accessToken;
                extractRequest.Left        = 5000;
                List <User> users = githubExtractor.Extract(extractRequest, userLoginList);

                // calculate the initial page of next.

                using (StreamWriter streamWriter = new StreamWriter(exportFile, true, Encoding.Default))
                {
                    foreach (User user in users)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append(user.name).Append(",");
                        sb.Append(user.followers).Append(",");
                        sb.Append(user.email).Append(",");
                        sb.Append(user.company).Append(",");
                        if (user.location != null)
                        {
                            sb.Append(user.location.Replace(',', '/')).Append(",");
                        }
                        else
                        {
                            sb.Append(user.location).Append(",");
                        }
                        streamWriter.WriteLine(sb.ToString());
                    }
                }
                if (extractRequest.Left > 0)
                {
                    break;
                }
            }
        }