// POST: api/Reception
        public bool Post([FromBody]EventDTO request)
        {
            using (var dbContext = new WeddingSiteBuilderEntities())
            {
                var wedding = dbContext.Weddings.FirstOrDefault(w => w.WeddingID == request.WeddingId);
                if (wedding != null)
                {
                    if (wedding.Receptions.Any())
                    {
                        var reception = wedding.Receptions.FirstOrDefault();
                        if (!string.IsNullOrWhiteSpace(request.LocationName)) reception.LocationName = request.LocationName;
                        if (!string.IsNullOrWhiteSpace(request.Address1)) reception.Address1 = request.Address1;
                        if (!string.IsNullOrWhiteSpace(request.City)) reception.City = request.City;
                        if (!string.IsNullOrWhiteSpace(request.State)) reception.StateProv = request.State;
                        if (!string.IsNullOrWhiteSpace(request.Zip)) reception.ZipCode = request.Zip;
                        if (request.Date != null) reception.ReceptionDateTime = request.Date.Value;

                        dbContext.SaveChanges();
                        return true;
                    }
                    wedding.Receptions.Add(new Reception()
                    {
                        LocationName = request.LocationName,
                        Address1 = request.Address1,
                        City = request.City,
                        StateProv = request.State,
                        ZipCode = request.Zip,
                        ReceptionDateTime = request.Date.HasValue ? request.Date.Value : DateTime.Now
                    });
                    var changesSaved = dbContext.SaveChanges();
                    return changesSaved == 1;
                }
                return false;
            }
        }
        // POST: api/Registration
        public long Post([FromBody]RegistrationDTO request)
        {
            int changesSaved = 0;
            try
            {
                using (var dbContext = new WeddingSiteBuilderEntities())
                {
                    var person = new Person()
                    {
                        Email = request.Email,
                        Password = request.Password,
                        FirstName = request.FirstName,
                        LastName = request.LastName
                    };
                    dbContext.People.Add(person);

                    var wedding = new Wedding();

                    dbContext.Weddings.Add(wedding);

                    changesSaved = dbContext.SaveChanges();

                    var attendee = new Attendee()
                    {
                        WeddingID = wedding.WeddingID,
                        PersonID = person.PersonID,
                        WeddingRole = request.BrideOrGroom == "Bride" ? "Bride" : "Groom",
                        Side = request.BrideOrGroom == "Bride" ? "Bride" : "Groom"
                    };

                    dbContext.Attendees.Add(attendee);

                    changesSaved += dbContext.SaveChanges();

                    if(changesSaved == 3)
                    {
                        return wedding.WeddingID;
                    }
                    else
                    {
                        return 0;
                    }
                }
            }
            catch(Exception)
            {
                return 0;
            }
        }
Ejemplo n.º 3
0
        // POST: api/RSVP
        public AttendeeWithRSVP Post([FromBody]AttendeeDTO request)
        {
            using(var dbContext = new WeddingSiteBuilderEntities())
            {
                var attendee = new Attendee()
                {
                    Side = request.Side,
                    WeddingID = request.WeddingId,
                    Person = new Person()
                    {
                        FirstName = request.FirstName,
                        LastName = request.LastName,
                        Email = request.Email
                    }
                };

                dbContext.Attendees.Add(attendee);
                var changesSaved = dbContext.SaveChanges();

                var rsvp = new RSVPLink()
                {
                    AttendeeID = attendee.AttendeeID,
                    GuidToken = new Guid()
                };

                dbContext.RSVPLinks.Add(rsvp);
                changesSaved += dbContext.SaveChanges();

                var attendeeWithRSVP = (AttendeeWithRSVP)attendee;
                attendeeWithRSVP.RSVP = rsvp;

                SendRSVPEmail(attendeeWithRSVP, dbContext);

                return attendeeWithRSVP;
            }
        }
 // GET: api/WeddingCouple/5
 public bool Get(int id)
 {
     int changesSaved = 0;
     using (var dbContext = new WeddingSiteBuilderEntities())
     {
         var wedding = new Wedding()
         {
             WeddingID = id,
             CoupleStory = "Oh My So, romantic",
             CreateDate = DateTime.Now,
             LastUpdated = DateTime.Now
         };
         dbContext.Weddings.Add(wedding);
         changesSaved = dbContext.SaveChanges();
     }
     return changesSaved > 0;
 }
        // POST: api/Attendee
        public bool Post([FromBody]AttendeeDTO request)
        {
            using(var dbContext = new WeddingSiteBuilderEntities())
            {
                var wedding = dbContext.Weddings.FirstOrDefault(w => w.WeddingID == request.WeddingId);
                if (wedding != null)
                {
                    if (request.AttendeeId.HasValue)
                    {
                        var existingAttendee = dbContext.Attendees.FirstOrDefault(a => a.AttendeeID == request.AttendeeId.Value);
                        if (existingAttendee != null)
                        {
                            if (!string.IsNullOrWhiteSpace(request.FirstName)) existingAttendee.Person.FirstName = request.FirstName;
                            if (!string.IsNullOrWhiteSpace(request.LastName)) existingAttendee.Person.LastName = request.LastName;
                            if (!string.IsNullOrWhiteSpace(request.Email)) existingAttendee.Person.Email = request.Email;
                            if (!string.IsNullOrWhiteSpace(request.Relationship)) existingAttendee.Relationship = request.Relationship;
                            if (!string.IsNullOrWhiteSpace(request.Role)) existingAttendee.WeddingRole = request.Role;
                            if (request.Role.ToLower() == "bride" || request.Role.ToLower() == "groom")
                            {
                                existingAttendee.Side = request.Role;
                            }
                            else if (request.Side.ToLower() == "bride" || request.Side.ToLower() == "groom")
                            {
                                existingAttendee.Side = request.Side;
                            }
                            if (!string.IsNullOrWhiteSpace(request.Blurb)) existingAttendee.PartyMemberBlurb = request.Blurb;
                            existingAttendee.PartyMember = request.PartyMember;

                            try
                            {
                                var changesSaved = dbContext.SaveChanges();
                                return true;
                            }
                            catch (Exception)
                            {
                                return false;
                            }

                        }
                    }
                    else if (!(string.IsNullOrWhiteSpace(request.FirstName) || string.IsNullOrWhiteSpace(request.LastName)))
                    {
                        if (request.Role.ToLower() == "bride" || request.Role.ToLower() == "groom")
                        {
                            request.Side = request.Role;
                        }
                        else if (!(request.Side.ToLower() == "bride" || request.Side.ToLower() == "groom"))
                        {
                            request.Side = "Bride";
                        }

                        var attendee = new Attendee()
                        {
                            Side = request.Side,
                            WeddingRole = request.Role,
                            Relationship = request.Relationship,
                            PartyMemberBlurb = request.Blurb,
                            PartyMember = request.PartyMember,
                            WeddingID = request.WeddingId,
                            Person = new Person()
                            {
                                FirstName = request.FirstName,
                                LastName = request.LastName,
                                Email = request.Email
                            }
                        };

                        dbContext.Attendees.Add(attendee);
                        var changesSaved = dbContext.SaveChanges();
                        return (changesSaved == 2);
                    }
                }
                return false;
            }
        }
Ejemplo n.º 6
0
        // POST: api/RSVP
        public AttendeeWithRSVP Post([FromBody]AttendeeDTO request)
        {
            using(var dbContext = new WeddingSiteBuilderEntities())
            {
                var attendee = new Attendee()
                {
                    Side = request.Side,
                    WeddingID = request.WeddingId,
                    Person = new Person()
                    {
                        FirstName = request.FirstName,
                        LastName = request.LastName,
                        Email = request.Email
                    }
                };
                try
                {
                    dbContext.Attendees.Add(attendee);
                    var changesSaved = dbContext.SaveChanges();

                    var rsvp = new RSVPLink()
                    {
                        AttendeeID = attendee.AttendeeID,
                        GuidToken = Guid.NewGuid(),
                        RSVPNameBlub = string.Empty,
                        IsAnswered = false
                    };

                    dbContext.RSVPLinks.Add(rsvp);
                    changesSaved += dbContext.SaveChanges();

                    var attendeeWithRSVP = new AttendeeWithRSVP
                    {
                        Attendee = new AttendeeModel(attendee),
                        RSVP = new RSVPLinkModel(rsvp)
                    };

                    SendRSVPEmail(attendee, rsvp, dbContext);

                    return attendeeWithRSVP;
                }
                catch(Exception)
                {
                    return null;
                }
            }
        }
Ejemplo n.º 7
0
        // Post: api/RSVP?RSVPLinkId=3&Count=2&Accepted=false
        public bool Post(long RSVPLinkId, int Count, bool Accepted)
        {
            using (var dbContext = new WeddingSiteBuilderEntities())
            {
                var rsvp = dbContext.RSVPLinks.FirstOrDefault(r => r.RSVPLinkID == RSVPLinkId);
                if (rsvp == null) return false;

                var attendee = dbContext.Attendees.FirstOrDefault(a => a.AttendeeID == rsvp.AttendeeID);
                attendee.NumberofRSVPs = Count;
                attendee.Attending = Accepted;
                rsvp.IsAnswered = true;

                dbContext.SaveChanges();
                return true;
            }
        }