Пример #1
0
        public ActionResult New()
        {
            var model = new Sponsor();

            ViewBag.Error = false;

            return View(model);
        }
Пример #2
0
        public Sponsor Insert(Sponsor sponsor)
        {
            sponsor.SponsorID = ObjectId.GenerateNewId();
            WriteConcernResult result = Sponsors.Insert(sponsor, new MongoInsertOptions { WriteConcern = WriteConcern.Acknowledged });

            if (result.Ok) { return sponsor; }
            return null;
        }
Пример #3
0
        public ActionResult New(Sponsor model)
        {
            ViewBag.Error = true;

            if (ModelState.IsValid)
            {
                Sponsor result = Context.Sponsors.Insert(model);

                if (result != null)
                {
                    return RedirectToAction("Edit", new { id = result.SponsorID });
                }
            }

            return View(model);
        }
Пример #4
0
        public bool Update(Sponsor model)
        {
            var sponsor = Sponsors.FindOneById(model.SponsorID);

            if (sponsor == null) { return false; }

            sponsor.Description = model.Description;
            sponsor.ImageUrl = model.ImageUrl;
            sponsor.Name = model.Name;
            sponsor.Url = model.Url;
            sponsor.ShowSponsor = model.ShowSponsor;
            sponsor.Order = model.Order;
            sponsor.Center = model.Center;

            WriteConcernResult result = Sponsors.Save(sponsor, new MongoInsertOptions { WriteConcern = WriteConcern.Acknowledged });
            return result.Ok;
        }
Пример #5
0
        private Coordinate getCenter(Sponsor sponsor, List<SponsorSpot> spots)
        {
            Coordinate coordinate = new Coordinate { Latitude = 0, Longitude = 0 };

            if (sponsor.Center == null)
            {
                var count = 0;

                foreach (var spot in spots)
                {
                    foreach (var coord in spot.SpotShape)
                    {
                        count++;
                        coordinate.Latitude += coord.Latitude;
                        coordinate.Longitude += coord.Longitude;
                    }
                }

                if (count > 0)
                {
                    coordinate.Latitude = coordinate.Latitude / count;
                    coordinate.Longitude = coordinate.Longitude / count;
                }

                sponsor.Center = coordinate;
                Context.Sponsors.Update(sponsor);
            }
            else { coordinate = sponsor.Center; }

            return coordinate;
        }