Beispiel #1
0
        public VNok Add(VNok nok)
        {
            using (_context)
            {
                var newnok = new NextOfKins()
                {
                    CellphoneNumber = nok.Cellphone,
                    Email           = nok.Email,
                    OtherNames      = nok.Othernames,
                    Surname         = nok.Surname,
                    PatientID       = nok.Patientid,
                    Active          = true
                };
                _context.NextOfKins.Add(newnok);
                _context.SaveChanges();
                nok.ID = newnok.ID;

                base.Audittrail(new VAuditTrails()
                {
                    Action      = "Insert",
                    ActionBy    = 1,
                    ActionDate  = DateTime.Now,
                    RecordTable = "NextOfKins",
                    RecordID    = nok.ID,
                    Record      = JsonConvert.SerializeObject(nok)
                });

                return(nok);
            }
        }
        public VContacts UpdatePatientContacts(VContacts contacts)
        {
            using (_context)
            {
                var dbcontacts = _context.Contacts.Where(t => t.PatientID == contacts.Patientid).FirstOrDefault();
                if (dbcontacts != null)
                {
                    dbcontacts.Cellphone  = contacts.Cellphone;
                    dbcontacts.Cellphone2 = contacts.Cellphone2;
                    dbcontacts.Email      = contacts.Email;

                    _context.SaveChanges();

                    base.Audittrail(new VAuditTrails()
                    {
                        Action      = "Update",
                        ActionBy    = 1,
                        ActionDate  = DateTime.Now,
                        RecordTable = "Contacts",
                        RecordID    = dbcontacts.ID,
                        Record      = JsonConvert.SerializeObject(contacts)
                    });
                }
                else
                {
                    var newcontact = new Contacts()
                    {
                        PatientID  = contacts.Patientid,
                        Cellphone  = contacts.Cellphone,
                        Cellphone2 = contacts.Cellphone2,
                        Email      = contacts.Email,
                        Active     = true
                    };


                    _context.Contacts.Add(newcontact);

                    _context.SaveChanges();

                    base.Audittrail(new VAuditTrails()
                    {
                        Action      = "Insert",
                        ActionBy    = 1,
                        ActionDate  = DateTime.Now,
                        RecordTable = "Contacts",
                        RecordID    = dbcontacts.ID,
                        Record      = JsonConvert.SerializeObject(contacts)
                    });
                }


                return(contacts);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Updates a user and ensures the share fields are included
        /// </summary>
        /// <param name="dto"></param>
        public override void UserUpdateForShare(FbDTO dto)
        {
            using (var context = new PHCEntities())
            {
                User usr = context.Users.Where(p => p.fbid == dto.fbid).SingleOrDefault();
                if (usr != null)
                {
                    usr.FirstName  = dto.Fname;
                    usr.LastName   = dto.Lname;
                    usr.Gender     = dto.Sex;
                    usr.Email      = dto.Email;
                    usr.fbid       = dto.fbid;
                    usr.acesstoken = dto.acctoken;
                    if (dto.SharedToFacebookOn > DateTime.MinValue)
                    {
                        usr.SharedToFacebookOn = dto.SharedToFacebookOn;
                    }
                    if (dto.SharedToPinterestOn > DateTime.MinValue)
                    {
                        usr.SharedToPinterestOn = dto.SharedToPinterestOn;
                    }
                    if (dto.SharedToTwitterOn > DateTime.MinValue)
                    {
                        usr.SharedToTwitterOn = dto.SharedToTwitterOn;
                    }

                    context.SaveChanges();
                }
            }
        }
Beispiel #4
0
        public override string Save_challenge(ChallengeDTO dto)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    Challenge ch = new Challenge();
                    ch.ChallengeName        = dto.ChallengeName;
                    ch.Description          = dto.Description;
                    ch.CatDescription       = dto.CatDescription;
                    ch.DogChallengeImage    = dto.dogchImg;
                    ch.CatChallengeImage    = dto.catchImg;
                    ch.BadgeID              = dto.BID;
                    ch.ChallengeCreatedDate = dto.ChcreatedDate;

                    context.AddToChallenges(ch);
                    context.SaveChanges();
                    msg = "success";
                }
                catch (Exception)
                {
                    msg = "fail";
                }
                return(msg);
            }
        }
        public void UpdateBiodata(VPatients patient)
        {
            using (_context = new PHCEntities())
            {
                var dbpatient = _context.Patients.Where(t => t.ID == patient.ID).FirstOrDefault();
                if (dbpatient != null)
                {
                    dbpatient.Title            = patient.Title;
                    dbpatient.Surname          = patient.Surname;
                    dbpatient.OtherNames       = patient.Othernames;
                    dbpatient.Gender           = patient.Gender;
                    dbpatient.DOB              = patient.DOB;
                    dbpatient.EnrollmentNumber = patient.Enrollmentnumber;
                    dbpatient.EnrollmentDate   = patient.Enrollmentdate;
                    dbpatient.OccupationID     = patient.Occupationid;

                    _context.SaveChanges();

                    base.Audittrail(new VAuditTrails()
                    {
                        Action      = "Update",
                        ActionBy    = 1,
                        ActionDate  = DateTime.Now,
                        RecordTable = "Patients",
                        RecordID    = dbpatient.ID,
                        Record      = JsonConvert.SerializeObject(patient)
                    });
                }
            }
        }
Beispiel #6
0
        public void DeleteNok(int id)
        {
            using (_context = new PHCEntities())
            {
                var dbnok = _context.NextOfKins.Where(t => t.ID == id).FirstOrDefault();
                if (dbnok != null)
                {
                    dbnok.Active = false;
                    _context.SaveChanges();

                    base.Audittrail(new VAuditTrails()
                    {
                        Action      = "Delete",
                        ActionBy    = 1,
                        ActionDate  = DateTime.Now,
                        RecordTable = "NextOfKins",
                        RecordID    = dbnok.ID,
                        Record      = JsonConvert.SerializeObject(new VNok()
                        {
                            ID         = dbnok.ID,
                            Othernames = dbnok.OtherNames,
                            Surname    = dbnok.Surname,
                            Cellphone  = dbnok.CellphoneNumber,
                            Email      = dbnok.Email,
                            Patientid  = dbnok.PatientID
                        })
                    });
                }
            }
        }
Beispiel #7
0
        public override string update_challenge(ChallengeDTO dto)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    Challenge chl = new Challenge();
                    chl = context.Challenges.Where(p => p.CHID == dto.CHID).SingleOrDefault();

                    if (chl != null)
                    {
                        chl.CHID                 = dto.CHID;
                        chl.ChallengeName        = dto.ChallengeName;
                        chl.Description          = dto.Description;
                        chl.BadgeID              = dto.BID;
                        chl.DogChallengeImage    = dto.dogchImg;
                        chl.CatChallengeImage    = dto.catchImg;
                        chl.ChallengeCreatedDate = Convert.ToDateTime(dto.SChcreatedDate);
                        chl.CatDescription       = dto.CatDescription;
                        context.SaveChanges();
                        msg = "success";
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
                return(msg);
            }
        }
Beispiel #8
0
        public override FbDTO Save_user(FbDTO dto)
        {
            using (var context = new PHCEntities())
            {
                FbDTO fb = new FbDTO();
                try
                {
                    User usr = new User();
                    usr.FirstName  = dto.Fname;
                    usr.LastName   = dto.Lname;
                    usr.Gender     = dto.Sex;
                    usr.Email      = dto.Email;
                    usr.fbid       = dto.fbid;
                    usr.acesstoken = dto.acctoken;
                    //    usr.Address = dto.Address;
                    //    usr.Link = dto.Link;

                    context.AddToUsers(usr);
                    context.SaveChanges();


                    fb.UID      = usr.UID;
                    fb.Email    = usr.Email;
                    fb.Fname    = usr.FirstName;
                    fb.acctoken = usr.acesstoken;
                    fb.fbid     = usr.fbid;
                }
                catch (Exception)
                {
                    throw;
                }
                return(fb);
            }
        }
Beispiel #9
0
        public override string Update_Wall(RewardsDTO dto)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    Wallpaper wall = new Wallpaper();
                    wall = context.Wallpapers.Where(p => p.WID == dto.WID).SingleOrDefault();
                    if (wall != null)
                    {
                        wall.Title     = dto.Title;
                        wall.WallImage = dto.WallImage;
                        context.SaveChanges();
                        msg = "success";
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
            }
            return(msg);
        }
Beispiel #10
0
        public override string Update_badge(badgeDTO dto)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    Badge bdg = new Badge();
                    bdg = context.Badges.Where(p => p.BId == dto.BID).SingleOrDefault();
                    if (bdg != null)
                    {
                        bdg.Badgename    = dto.Badgename;
                        bdg.Badgelogo    = dto.badgeImage;
                        bdg.createdDate  = DateTime.Now;
                        bdg.CDescription = dto.cdescription;
                        bdg.LDescription = dto.ldescription;
                        context.SaveChanges();
                        msg = "success";
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
            }
            return(msg);
        }
        public void DeleteContact(int id)
        {
            using (_context = new PHCEntities())
            {
                var dbcontact = _context.Contacts.Where(t => t.ID == id).FirstOrDefault();
                if (dbcontact != null)
                {
                    dbcontact.Active = false;
                    _context.SaveChanges();

                    base.Audittrail(new VAuditTrails()
                    {
                        Action      = "Delete",
                        ActionBy    = 1,
                        ActionDate  = DateTime.Now,
                        RecordTable = "Contacts",
                        RecordID    = dbcontact.ID,
                        Record      = JsonConvert.SerializeObject(new VContacts()
                        {
                            Cellphone2 = dbcontact.Cellphone2,
                            Cellphone  = dbcontact.Cellphone,
                            Email      = dbcontact.Email,
                            Patientid  = dbcontact.PatientID
                        })
                    });
                }
            }
        }
Beispiel #12
0
        public override string Save_badge(badgeDTO dto)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    Badge bg = new Badge();
                    bg.Badgename    = dto.Badgename;
                    bg.Badgelogo    = dto.badgeImage;
                    bg.createdDate  = DateTime.Now;
                    bg.CDescription = dto.cdescription;
                    bg.LDescription = dto.ldescription;

                    context.AddToBadges(bg);
                    context.SaveChanges();
                    msg = "success";
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
                return(msg);
            }
        }
Beispiel #13
0
 public override int UpdateUID(PetProfileDTO dt)
 {
     using (var context = new PHCEntities())
     {
         try
         {
             PetProfile pp = context.PetProfiles.Where(p => p.PID == dt.PID).SingleOrDefault();
             if (pp != null)
             {
                 pp.UID = dt.UID;
                 context.SaveChanges();
                 int c = pp.PID;
                 return(c);
             }
             else
             {
                 return(0);
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
        public void MakeNOKpatient(int id)
        {
            var nok = _context.NextOfKins.Where(t => t.ID == id).FirstOrDefault();

            if (nok != null)
            {
                var newpatient = new Patients()
                {
                    Surname    = nok.Surname,
                    OtherNames = nok.OtherNames,
                    Active     = true
                };

                _context.Patients.Add(newpatient);

                _context.SaveChanges();
                var newpatientcontact = new Contacts()
                {
                    PatientID = newpatient.ID,
                    Cellphone = nok.CellphoneNumber,
                    Active    = true
                };

                _context.Contacts.Add(newpatientcontact);

                _context.SaveChanges();

                base.Audittrail(new VAuditTrails()
                {
                    Action      = "Insert",
                    ActionBy    = 1,
                    ActionDate  = DateTime.Now,
                    RecordTable = "Patients",
                    RecordID    = newpatient.ID,
                    Record      = JsonConvert.SerializeObject(new VPatients()
                    {
                        ID         = newpatient.ID,
                        Othernames = newpatient.OtherNames,
                        Surname    = newpatient.Surname,
                    })
                });
            }
        }
Beispiel #15
0
        public virtual void Audittrail(VAuditTrails audit)
        {
            _context.AuditTrails.Add(new AuditTrails()
            {
                Action      = audit.Action,
                Actionby    = audit.ActionBy,
                ActionDate  = audit.ActionDate,
                Record      = audit.Record,
                RecordTable = audit.RecordTable,
                RecordID    = audit.RecordID
            });

            _context.SaveChanges();
        }
Beispiel #16
0
        /// <summary>
        /// Indicates this prize has been received
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="prizeId"></param>
        public void MarkPrizeAsRedeemed(int userId, int prizeId)
        {
            using (var context = new PHCEntities())
            {
                var reward = context.Rewards.Where(x => x.UID == userId && x.WID == prizeId).FirstOrDefault();
                if (reward == null)
                {
                    return;
                }

                reward.DateClaimed = DateTime.UtcNow;
                context.SaveChanges();
            }
        }
 public VOccupations Add(VOccupations occupation)
 {
     using (_context)
     {
         var newoccupation = new Occupations()
         {
             Occupation = occupation.Occupation,
             Active     = true
         };
         _context.Occupations.Add(newoccupation);
         _context.SaveChanges();
         occupation.ID = newoccupation.ID;
         return(occupation);
     }
 }
        public void DeletePatient(int patientid)
        {
            using (_context = new PHCEntities())
            {
                var dbpatient = _context.Patients.Where(t => t.ID == patientid).FirstOrDefault();
                if (dbpatient != null)
                {
                    dbpatient.Active = false;
                    _context.SaveChanges();

                    base.Audittrail(new VAuditTrails()
                    {
                        Action      = "Delete",
                        ActionBy    = 1,
                        ActionDate  = DateTime.Now,
                        RecordTable = "Patients",
                        RecordID    = dbpatient.ID,
                        Record      = JsonConvert.SerializeObject(new VPatients()
                        {
                            DOB              = dbpatient.DOB,
                            Enrollmentdate   = dbpatient.EnrollmentDate,
                            Enrollmentnumber = dbpatient.EnrollmentNumber,
                            Gender           = dbpatient.Gender,
                            ID           = dbpatient.ID,
                            Occupationid = dbpatient.OccupationID,
                            Othernames   = dbpatient.OtherNames,
                            Surname      = dbpatient.Surname,
                            Title        = dbpatient.Title
                        })
                    });
                }

                //Delete contacts
                var contacts = dbpatient.Contacts;
                foreach (var contact in contacts)
                {
                    _contacts.DeleteContact(contact.ID);
                }

                //Delete NoK
                var noks = dbpatient.NextOfKins;
                foreach (var nok in noks)
                {
                    _nok.DeleteNok(nok.ID);
                }
            }
        }
Beispiel #19
0
        public override string delete_badge(int id)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    Badge bdg = new Badge();
                    bdg = context.Badges.Where(p => p.BId == id).SingleOrDefault();
                    if (bdg != null)
                    {
                        context.DeleteObject(bdg);
                    }


                    List <Challenge> profile = context.Challenges.Where(m => m.BadgeID == id).ToList();

                    if (profile != null)
                    {
                        foreach (Challenge n in profile)
                        {
                            context.DeleteObject(n);
                        }
                    }

                    List <PetEarnBadge> pearn = context.PetEarnBadges.Where(m => m.BID == id).ToList();

                    if (pearn != null)
                    {
                        foreach (PetEarnBadge n in pearn)
                        {
                            context.DeleteObject(n);
                        }
                    }

                    context.SaveChanges();

                    msg = "success";
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
            }
            return(msg);
        }
Beispiel #20
0
        public override string deleteuser(int id)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    User usr = context.Users.Where(p => p.UID == id).SingleOrDefault();

                    context.DeleteObject(usr);


                    List <PetEarnBadge> pern = context.PetEarnBadges.Where(k => k.UID == id).ToList();

                    if (pern != null)
                    {
                        foreach (PetEarnBadge c in pern)
                        {
                            context.DeleteObject(c);
                        }
                    }


                    List <PetProfile> profile = context.PetProfiles.Where(m => m.UID == id).ToList();

                    if (profile != null)
                    {
                        foreach (PetProfile n in profile)
                        {
                            context.DeleteObject(n);
                        }
                    }

                    context.SaveChanges();

                    msg = "success";
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
                return(msg);
            }
        }
Beispiel #21
0
 /// <summary>
 /// Indicates that a user is now eligable for a particular reward/prize
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="prizeId"></param>
 public void AssignPrizeToUser(int userId, int prizeId)
 {
     using (var context = new PHCEntities())
     {
         var reward = context.Rewards.Where(x => x.WID == prizeId && x.UID == userId).FirstOrDefault();
         if (reward == null) // if there's not already an entry, then let's assign this prize
         {
             reward = new Reward()
             {
                 DateUnlocked = DateTime.UtcNow,
                 UID          = userId,
                 WID          = prizeId
             };
             context.Rewards.AddObject(reward);
             context.SaveChanges();
         }
     }
 }
 public VVillages Add(VVillages village)
 {
     using (_context)
     {
         var newvillage = new Villages()
         {
             WardID  = village.Wardid,
             Village = village.Village,
             Active  = true
         };
         _context.Villages.Add(newvillage);
         _context.SaveChanges();
         village.ID = newvillage.ID;
         //village.Subcountyid = newvillage.Wards.SubCountyID;
         //village.Countyid = newvillage.Wards.SubCounties.CountyID;
         return(village);
     }
 }
        public void UpdatePatientLocation(int patientid, int Villageid)
        {
            using (_context = new PHCEntities())
            {
                var dbpatient = _context.Patients.Where(t => t.ID == patientid).FirstOrDefault();
                if (dbpatient != null)
                {
                    dbpatient.LocationID = Villageid;
                    _context.SaveChanges();

                    base.Audittrail(new VAuditTrails()
                    {
                        Action      = "Update",
                        ActionBy    = 1,
                        ActionDate  = DateTime.Now,
                        RecordTable = "Patients",
                        RecordID    = dbpatient.ID,
                        Record      = JsonConvert.SerializeObject(new { LocationID = Villageid })
                    });
                }
            }
        }
Beispiel #24
0
        public override FbDTO update_user(FbDTO dto)
        {
            using (var context = new PHCEntities())
            {
                FbDTO fb = new FbDTO();
                try
                {
                    User usr = context.Users.Where(p => p.fbid == dto.fbid).SingleOrDefault();
                    if (usr != null)
                    {
                        usr.FirstName  = dto.Fname;
                        usr.LastName   = dto.Lname;
                        usr.Gender     = dto.Sex;
                        usr.Email      = dto.Email;
                        usr.fbid       = dto.fbid;
                        usr.acesstoken = dto.acctoken;

                        //   usr.Address = dto.Address;

                        //    usr.Link = dto.Link;


                        context.SaveChanges();
                    }


                    fb.UID      = usr.UID;
                    fb.Email    = usr.Email;
                    fb.Fname    = usr.FirstName;
                    fb.acctoken = usr.acesstoken;
                    fb.fbid     = usr.fbid;
                }
                catch (Exception)
                {
                    throw;
                }
                return(fb);
            }
        }
Beispiel #25
0
 public override PetProfileDTO SavePetDetSignUp(PetProfileDTO dto)
 {
     using (var context = new PHCEntities())
     {
         try
         {
             PetProfileDTO pdto = new PetProfileDTO();
             PetProfile    pp   = new PetProfile();
             pp.UID         = dto.UID;
             pp.PetName     = dto.PetName;
             pp.PetBreed    = dto.PetBreed;
             pp.PetCategory = dto.pcid.ToString();
             context.AddToPetProfiles(pp);
             context.SaveChanges();
             pdto.PID = pp.PID;
             return(pdto);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Beispiel #26
0
        public override string Save_Wallpaper(RewardsDTO adto)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    Wallpaper bg = new Wallpaper();
                    bg.Title     = adto.Title;
                    bg.WallImage = adto.WallImage;

                    context.AddToWallpapers(bg);
                    context.SaveChanges();
                    msg = "success";
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
                return(msg);
            }
        }
        public VPatients AddBiodata(VPatients patient)
        {
            using (_context = new PHCEntities())
            {
                var newpatient = new Patients()
                {
                    Title            = patient.Title,
                    Surname          = patient.Surname,
                    OtherNames       = patient.Othernames,
                    Gender           = patient.Gender,
                    DOB              = patient.DOB,
                    EnrollmentNumber = patient.Enrollmentnumber,
                    EnrollmentDate   = patient.Enrollmentdate,
                    OccupationID     = patient.Occupationid,
                    Active           = true
                };

                _context.Patients.Add(newpatient);
                _context.SaveChanges();

                patient.ID = newpatient.ID;

                base.Audittrail(new VAuditTrails()
                {
                    Action      = "Insert",
                    ActionBy    = 1,
                    ActionDate  = DateTime.Now,
                    RecordTable = "Patients",
                    RecordID    = patient.ID,
                    Record      = JsonConvert.SerializeObject(patient)
                });


                patient.Occupation = newpatient.Occupations?.Occupation;
            }
            return(patient);
        }
        public List <VVillages> AddPatientLocation(int patientid, int Villageid)
        {
            using (_context = new PHCEntities())
            {
                List <VVillages> villagelist = new List <VVillages>();
                var dbpatient = _context.Patients.Include("Villages").Where(t => t.ID == patientid).FirstOrDefault();
                if (dbpatient != null)
                {
                    dbpatient.LocationID = Villageid;
                    _context.SaveChanges();

                    var patientvillage = dbpatient.Villages;
                    if (patientvillage != null)
                    {
                        villagelist.Add(new VVillages()
                        {
                            ID          = patientvillage.ID,
                            Countyid    = patientvillage.Wards.SubCounties.CountyID,
                            Subcountyid = patientvillage.Wards.SubCountyID,
                            Wardid      = patientvillage.WardID,
                            Village     = patientvillage.Village,
                        });
                    }
                    base.Audittrail(new VAuditTrails()
                    {
                        Action      = "Update",
                        ActionBy    = 1,
                        ActionDate  = DateTime.Now,
                        RecordTable = "Patients",
                        RecordID    = dbpatient.ID,
                        Record      = JsonConvert.SerializeObject(new { LocationID = Villageid })
                    });
                }

                return(villagelist);
            }
        }
Beispiel #29
0
        public override string delete_wall(int id)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    Wallpaper wall = new Wallpaper();
                    wall = context.Wallpapers.Where(p => p.WID == id).SingleOrDefault();
                    if (wall != null)
                    {
                        context.DeleteObject(wall);
                        context.SaveChanges();
                        msg = "success";
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
            }
            return(msg);
        }
Beispiel #30
0
        public override string delete_challenge(int id)
        {
            string msg = "";

            using (var context = new PHCEntities())
            {
                try
                {
                    Challenge chl = new Challenge();
                    chl = context.Challenges.Where(p => p.CHID == id).SingleOrDefault();
                    if (chl != null)
                    {
                        context.DeleteObject(chl);
                    }

                    List <PetEarnBadge> pearn = context.PetEarnBadges.Where(m => m.CID == id).ToList();

                    if (pearn != null)
                    {
                        foreach (PetEarnBadge n in pearn)
                        {
                            context.DeleteObject(n);
                        }
                    }

                    msg = "success";

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
            }
            return(msg);
        }