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);
            }
        }
Ejemplo n.º 2
0
 public JsonResult UpdatePatientContacts(VContacts contacts)
 {
     try
     {
         if (contacts.Patientid == 0)
         {
             return(Json(new { Result = "ERROR", Message = "Please Add Biodata First" }));
         }
         else
         {
             //Update patient contacts
             var addedcontact = _contact.UpdatePatientContacts(contacts);
             return(Json(new { Result = "OK", Record = addedcontact }));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { Result = "ERROR", Message = ex.Message }));
     }
 }