Пример #1
0
        public void updateBFKSRegistration(WebBFKSRegistration webRegistration)
        {
            // Check if registration is enabled for this event occurrence.
            EventOccurrence eventOccurrence = db.EventOccurrences
                                              .SingleOrDefault(e => e.id == webRegistration.eventOccurrenceId);

            if (eventOccurrence != null)
            {
                if (!eventOccurrence.isActive)
                {
                    throw new Exception("You cannot register for this event because it is not active");
                }
                BFKSRegistration registration = db.BFKSRegistrations
                                                .SingleOrDefault(r => r.id == webRegistration.id);
                if (registration != null && (registration.userId == me.id || me.type == "admin"))
                {
                    registration.eventOccurrenceId = webRegistration.eventOccurrenceId;
                    // Only allow admins to manually mark registration as being paid (e.g. in person with cash/check).
                    if (me.type == "admin")
                    {
                        registration.isPaid = webRegistration.isPaid;
                    }
                    registration.teamName      = webRegistration.teamName;
                    registration.teamCaptainId = webRegistration.teamCaptainId;

                    db.BFKSBowlers.RemoveRange(registration.bowlers);

                    registration.bowlers = new List <BFKSBowler>();
                    foreach (WebBFKSBowler webBowler in webRegistration.bowlers)
                    {
                        BFKSBowler bowler = new BFKSBowler();
                        bowler.userId     = webBowler.userId;
                        bowler.name       = webBowler.name;
                        bowler.tshirtSize = webBowler.tshirtSize;
                        registration.bowlers.Add(bowler);
                    }

                    db.SaveChanges();
                }
                else
                {
                    throw new PermissionDeniedException();
                }
            }
            else
            {
                throw new PermissionDeniedException();
            }
        }
        public HttpResponseMessage Put(int id, WebBFKSRegistration registration)
        {
            if (!ModelState.IsValid || registration == null || id != registration.id)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }

            try
            {
                repo.updateBFKSRegistration(registration);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e));
            }
        }
        public HttpResponseMessage Post(WebBFKSRegistration registration)
        {
            if (!ModelState.IsValid || registration == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }

            try
            {
                int id = repo.addBFKSRegistration(registration);
                return(Request.CreateResponse(HttpStatusCode.Created, id));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e));
            }
        }
Пример #4
0
        public int addBFKSRegistration(WebBFKSRegistration webRegistration)
        {
            // Check if registration is enabled for this event occurrence.
            EventOccurrence eventOccurrence = db.EventOccurrences
                                              .SingleOrDefault(e => e.id == webRegistration.eventOccurrenceId);

            if (eventOccurrence != null)
            {
                if (!eventOccurrence.isActive)
                {
                    throw new Exception("You cannot register for this event because it is not active");
                }
                BFKSRegistration registration = new BFKSRegistration();
                registration.eventOccurrenceId = webRegistration.eventOccurrenceId;
                registration.userId            = this.me.id;
                registration.isPaid            = false;
                registration.teamName          = webRegistration.teamName;
                registration.teamCaptainId     = webRegistration.teamCaptainId;
                registration.dateCreated       = DateTime.UtcNow;

                registration.bowlers = new List <BFKSBowler>();
                foreach (WebBFKSBowler webBowler in webRegistration.bowlers)
                {
                    BFKSBowler bowler = new BFKSBowler();
                    bowler.userId     = webBowler.userId;
                    bowler.name       = webBowler.name;
                    bowler.tshirtSize = webBowler.tshirtSize;
                    registration.bowlers.Add(bowler);
                }

                db.BFKSRegistrations.Add(registration);
                db.SaveChanges();

                return(registration.id);
            }
            else
            {
                throw new PermissionDeniedException();
            }
        }