Пример #1
0
        public void dismissInvitation([FromBody] Invitation Inv)
        {
            ReviveCommunicationsDBEntities3 db = new ReviveCommunicationsDBEntities3();

            db.Configuration.ProxyCreationEnabled = false;

            Person_Invitation thisInv = db.Person_Invitation.Where(x => x.InvitationID == Inv.InvitationID).FirstOrDefault();

            try
            {
                thisInv.InvitationStatus = true;

                db.SaveChanges();
            }
            catch (Exception e)
            {
            }
        }
Пример #2
0
        public void SendInvitation([FromBody] dynamic inv)
        {
            ReviveCommunicationsDBEntities3 db = new ReviveCommunicationsDBEntities3();

            db.Configuration.ProxyCreationEnabled = false;
            DbContextTransaction transaction = db.Database.BeginTransaction();

            if (inv != null) //if object not null
            {
                try
                {
                    Invitation dynamicInvitation = new Invitation();

                    //create new announcement based on Object received
                    dynamicInvitation.InvitationDate           = inv.InvitationDate.ToString("yyyy-mm-dd");
                    dynamicInvitation.InvitationSenderPersonID = inv.PersonID;
                    dynamicInvitation.InvitationDetail         = inv.InvitationDetail;
                    dynamicInvitation.StartTime = inv.StartTime.ToString("HH:mm");
                    dynamicInvitation.EndTime   = inv.EndTime.ToString("HH:mm");
                    dynamicInvitation.Summary   = inv.Summary;


                    db.Invitations.Add(dynamicInvitation);                                                    // add Invite to database
                    db.SaveChanges();                                                                         //save

                    string d = inv.InvitationDetail;                                                          //write new Invite detail to string

                    Invitation created = db.Invitations.Where(x => x.InvitationDetail == d).FirstOrDefault(); //retrieve created Invite



                    foreach (dynamic p in inv.SelectedReceivers)// foreach person in receiver list
                    {
                        //create new Person_Announcement entry
                        Person_Invitation person_Invitation = new Person_Invitation();
                        person_Invitation.PersonID     = p.PersonID;
                        person_Invitation.InvitationID = created.InvitationID;


                        db.Person_Invitation.Add(person_Invitation);// Add to data base
                        db.SaveChanges();
                    }
                    int id = db.Invitations.OrderByDescending(x => x.InvitationID).Select(x => x.InvitationID).FirstOrDefault();

                    Audit_Trail auditLog = new Audit_Trail();
                    auditLog.PersonID         = inv.PersonID;
                    auditLog.EventDescription = "Sent invitation with ID: " + id;
                    auditLog.EventDateTime    = DateTime.Now;
                    db.Audit_Trail.Add(auditLog);

                    db.SaveChanges();//save
                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    dynamic toReturn = new ExpandoObject();
                    toReturn = e.Message + e.InnerException;// else error
                }
            }
        }