Exemple #1
0
        public bool CreateVisit(VisitCreate model)
        {
            var entity = new Visit()
            {
                OwnerId    = _ownerId,
                VisitDate  = model.VisitDate,
                ParkId     = model.ParkId,
                HomeTeamId = model.HomeTeamId,
                AwayTeamId = model.AwayTeamId,
                VisitorId  = model.VisitorId,
                GotPin     = model.GotPin,
                GotPhoto   = model.GotPhoto,
            };

            using (var ctx = new ApplicationDbContext())
            {
                //UpdateTotalVisits(entity.VisitorId, 1, ctx);
                //UpdateVisitCount(entity.ParkId, 1, ctx);

                //if (entity.GotPin == true)
                //{
                //    UpdatePinCount(entity.ParkId, 1, ctx);
                //    UpdatePersonalPins(entity.VisitorId, 1, ctx);
                //}
                //if (entity.GotPhoto == true)
                //    UpdatePhotoCount(entity.ParkId, 1, ctx);

                ctx.Visits.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public IHttpActionResult Post(VisitCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            VisitService service = CreateVisitService();

            if (service.CreateVisit(model))
            {
                return(Ok());
            }

            return(InternalServerError());
        }
        public bool CreateVisit(VisitCreate model)
        {
            var entity = new VisitEntity
            {
                GameID    = model.GameID,
                VisitorID = model.VisitorID,
                GotPin    = model.GotPin,
                TookPhoto = model.TookPhoto,
                OwnerID   = _userID
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Visits.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Create(VisitCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateVisitService();

            if (service.CreateVisit(model))
            {
                TempData["SaveResult"] = "New Visit Added";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Visit could not be added.");
            return(View(model));
        }