public async Task <string> DeleteUser(int id) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Invitation invite = opiddailycontext.Invitations.Where(i => i.Id == id).SingleOrDefault(); if (invite != null) { var user = await UserManager.FindByNameAsync(invite.UserName); if (user != null) { UserManager.Delete(user); opiddailycontext.Invitations.Remove(invite); opiddailycontext.SaveChanges(); return("Success"); } else { opiddailycontext.Invitations.Remove(invite); opiddailycontext.SaveChanges(); return("Success"); } } return("Failure"); } }
public static void EditVisit(int nowServing, VisitViewModel vvm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Client client = opiddailycontext.Clients.Find(nowServing); if (client != null) { AncientCheck ancientCheck = opiddailycontext.AncientChecks.Find(vvm.Id); if (ancientCheck != null) { ancientCheck.Date = vvm.Date; ancientCheck.Num = Convert.ToInt32(vvm.Check); ancientCheck.Service = vvm.Item; ancientCheck.Disposition = vvm.Status; ancientCheck.Notes = vvm.Notes; opiddailycontext.SaveChanges(); return; } RCheck rcheck = opiddailycontext.RChecks.Find(vvm.Id); if (rcheck != null) { rcheck.Date = vvm.Date; rcheck.Num = Convert.ToInt32(vvm.Check); rcheck.Service = vvm.Item; rcheck.Disposition = vvm.Status; rcheck.Notes = vvm.Notes; opiddailycontext.SaveChanges(); return; } PocketCheck pcheck = opiddailycontext.PocketChecks.Find(vvm.Id); if (pcheck != null) { pcheck.Date = vvm.Date; pcheck.Item = vvm.Item; pcheck.Num = Convert.ToInt32(vvm.Check); pcheck.Disposition = vvm.Status; pcheck.Notes = vvm.Notes; opiddailycontext.SaveChanges(); return; } } } }
public static void DeletePocketCheck(int nowServing, int id) { try { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Client client = opiddailycontext.Clients.Find(nowServing); if (client != null) { PocketCheck pcheck = opiddailycontext.PocketChecks.Where(p => p.ClientId == nowServing).SingleOrDefault(); if (pcheck != null) { DeleteVisitNotes(pcheck.Id); opiddailycontext.PocketChecks.Remove(pcheck); opiddailycontext.SaveChanges(); } } } } catch (Exception e) { Log.Error(string.Format("Could not delete client with id = {0} Error {1}", nowServing, e.Message)); } }
public static void DeleteMBVD(MBVDViewModel mbvdvm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { MBVD mbvd = opiddailycontext.MBVDS.Find(mbvdvm.MBVDId); opiddailycontext.MBVDS.Remove(mbvd); opiddailycontext.SaveChanges(); } }
public static void DeleteVisitNotes(int id) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { List <TextMsg> textmsgs = opiddailycontext.TextMsgs.Where(m => m.Vid == id).ToList(); opiddailycontext.TextMsgs.RemoveRange(textmsgs); opiddailycontext.SaveChanges(); } }
public static void AddMBVD(MBVDViewModel mbvdvm) { MBVD mbvd = MBVDViewModelToMBVD(mbvdvm); using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { opiddailycontext.MBVDS.Add(mbvd); opiddailycontext.SaveChanges(); } }
public static void AddAgency(AgencyViewModel avm) { Agency agency = AgencyViewModelToAgency(avm); using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { opiddailycontext.Agencies.Add(agency); opiddailycontext.SaveChanges(); } }
public static void DeleteAgency(AgencyViewModel avm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Agency agency = opiddailycontext.Agencies.Find(avm.Id); opiddailycontext.Agencies.Remove(agency); opiddailycontext.SaveChanges(); } }
public static void ExtendInvitation(InvitationViewModel ivm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Invitation invite = InvitationViewModelToInvite(ivm); opiddailycontext.Invitations.Add(invite); opiddailycontext.SaveChanges(); } // SendEmailInvitation(invitation); }
public static void EditVisitNote(VisitNoteModel vnm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { List <TextMsg> textmsgs = opiddailycontext.TextMsgs.Where(m => m.Vid == vnm.Id).ToList(); if (textmsgs.Count == 1) { TextMsg textmsg = textmsgs[0]; VisitNoteModelToTextMsg(vnm, textmsg); opiddailycontext.SaveChanges(); } } }
public static void DeleteVisitNote(int id) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { List <TextMsg> textmsgs = opiddailycontext.TextMsgs.Where(m => m.Vid == id).ToList(); TextMsg textmsg = textmsgs[0]; if (textmsgs.Count == 1) { opiddailycontext.TextMsgs.Remove(textmsg); opiddailycontext.SaveChanges(); } } }
public static void AddVisitNote(int nowServing, int vid, string sender, VisitNoteModel vnm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Client client = opiddailycontext.Clients.Find(nowServing); opiddailycontext.Entry(client).Collection(c => c.TextMsgs).Load(); TextMsg textmsg = VisitNoteModelToTextMsg(vnm, vid); client.TextMsgs.Add(textmsg); opiddailycontext.SaveChanges(); } }
public static void EditMBVD(MBVDViewModel mbvdvm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { MBVD mbvd = opiddailycontext.MBVDS.Find(mbvdvm.Id); if (mbvd != null) { mbvd.MBVDId = mbvdvm.MBVDId; mbvd.MBVDName = mbvdvm.MBVDName; mbvd.IsActive = (mbvdvm.IsActive == "Yes" ? true : false); opiddailycontext.SaveChanges(); } } }
public static Invitation AcceptedInvitation(string userName, string email) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Invitation invite = opiddailycontext.Invitations.Where(i => i.UserName == userName).SingleOrDefault(); if (invite != null && invite.Email == email) { invite.Accepted = Extras.DateTimeToday(); opiddailycontext.SaveChanges(); return(invite); } return(null); } }
public static string EditUser(InvitationViewModel invite) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Invitation invitation = opiddailycontext.Invitations.Find(invite.Id); if (invitation != null && invitation.Accepted != (System.DateTime)System.Data.SqlTypes.SqlDateTime.Null) { return("Registered"); } invitation.UserName = invite.UserName; invitation.Email = invite.Email; invitation.Role = invite.Role; opiddailycontext.SaveChanges(); return("Success"); } }
public static void AddPocketCheck(int nowServing, VisitViewModel vvm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Client client = opiddailycontext.Clients.Find(nowServing); if (client != null) { opiddailycontext.PocketChecks.Add(NewPocketCheck(client, vvm)); // A pocket check must always have a corresponding check in the Research Table, // because Service Tickets are generated from the visit history in the Research // table, not by using any pocket checks. So, when we add a new pocket check // we must also add a new corresponding research check. opiddailycontext.RChecks.Add(NewRCheck(client, vvm)); opiddailycontext.SaveChanges(); } } }
public static void EditUserAgencyId(int oldAgencyId, int newAgencyId) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { List <Invitation> invitations = opiddailycontext.Invitations.Where(i => i.AgencyId == oldAgencyId).ToList(); using (IdentityDB identitycontext = new IdentityDB()) { var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(identitycontext)); foreach (Invitation invite in invitations) { // The UserName in the Invitations table is the same as the UserName in table AspNetUsers. ApplicationUser user = UserManager.FindByName(invite.UserName); user.AgencyId = newAgencyId; UserManager.Update(user); invite.AgencyId = newAgencyId; } } opiddailycontext.SaveChanges(); } }
public static void EditAgency(AgencyViewModel avm) { using (OpidDailyDB opiddailycontext = new OpidDailyDB()) { Agency agency = opiddailycontext.Agencies.Find(avm.Id); List <Client> clients = opiddailycontext.Clients.Where(c => c.AgencyId == agency.AgencyId).ToList(); foreach (Client c in clients) { c.AgencyId = avm.AgencyId; } Users.EditUserAgencyId(agency.AgencyId, avm.AgencyId); agency.AgencyId = avm.AgencyId; agency.AgencyName = avm.AgencyName; agency.ContactPerson = avm.ContactPerson; agency.Phone = avm.Phone; agency.Email = avm.Email; agency.IsActive = (avm.IsActive == "Yes" ? true : false); opiddailycontext.SaveChanges(); } }