//===========================================
        public void addPhones(int cId, string phone1, int shreha1, string phone2, int shreha2, string phone3, int shreha3)
        {
            if (phone1 != null)
            {
                phones ph1 = new phones();
                ph1.clientId  = cId;
                ph1.number    = phone1;
                ph1.sharehaId = shreha1;
                DB.phones.Add(ph1);
                DB.SaveChanges();
            }
            if (phone2 != null)
            {
                phones ph2 = new phones();
                ph2.clientId  = cId;
                ph2.number    = phone2;
                ph2.sharehaId = shreha2;
                DB.phones.Add(ph2);
                DB.SaveChanges();
            }
            if (phone3 != null)
            {
                phones ph3 = new phones();
                ph3.clientId  = cId;
                ph3.number    = phone3;
                ph3.sharehaId = shreha3;
                DB.phones.Add(ph3);
                DB.SaveChanges();
            }
        }
//================================================================================

        public JsonResult delete_phone(int phId)
        {
            try
            {
                phones ph = DB.phones.Where(p => p.id == phId).Single();
                DB.phones.Remove(ph);
                DB.SaveChanges();

                return(Json(new { msg = "تم حذف الرقم بنجاح" }));
            }
            catch
            {
                return(Json(new { msg = "لا يمكن حذف هذا الرقم" }));
            }
        }
        public JsonResult update_phone_of_client(int phId, string phone, int sharehaId)
        {
            try
            {
                phones ph = DB.phones.Where(p => p.id == phId).Single();
                ph.number    = phone;
                ph.sharehaId = sharehaId;

                DB.Entry(ph).State = EntityState.Modified;
                DB.SaveChanges();

                return(Json(new { msg = "تمت تعديل رقم التليفون بنجاح" }));
            }
            catch
            {
                return(Json(new { msg = "لم تتم عمليه التعديل حاول مره اخري" }));
            }
        }
        public JsonResult add_phone_to_client(int cId, string phone, int sharehaId)
        {
            try
            {
                phones ph = new phones();
                ph.clientId  = cId;
                ph.number    = phone;
                ph.sharehaId = sharehaId;

                DB.phones.Add(ph);
                DB.SaveChanges();

                return(Json(new { msg = "تمت اضافه رقم التليفون بنجاح" }));
            }
            catch
            {
                return(Json(new { msg = "لم تتم عمليه الاضافه حاول مره اخري" }));
            }
        }
Exemple #5
0
 public phones GetById(string id)
 {
     try
     {
         phones phone = null;
         foreach (var _phone in Get())
         {
             if (_phone.Id == id)
             {
                 phone = _phone;
             }
         }
         //phone = _phones.Find<phones>((p) =>(p.Id == id.TrimEnd())).FirstOrDefault();
         return(phone);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
//===========================================
        public void updatePhones(int cId, string phone1, int shreha1, string phone2, int shreha2, string phone3, int shreha3)
        {
            bool first = false, second = false, third = false;

            List <phones> phoneList = DB.phones.Where(p => p.clientId == cId).ToList();

            if (phoneList.Count() == 3)
            {
                first  = true;
                second = true;
                third  = true;
            }
            else if (phoneList.Count() == 2)
            {
                first  = true;
                second = true;
            }
            else if (phoneList.Count() == 1)
            {
                first = true;
            }


            if (phone1 != "" && first)
            {
                phones ph1 = phoneList[0];
                ph1.number          = phone1;
                ph1.sharehaId       = shreha1;
                DB.Entry(ph1).State = EntityState.Modified;
                DB.SaveChanges();
            }
            else if (phone1 != "" && !first)
            {
                phones ph1 = new phones();
                ph1.clientId  = cId;
                ph1.number    = phone1;
                ph1.sharehaId = shreha1;
                DB.phones.Add(ph1);
                DB.SaveChanges();
            }


            if (phone2 != "" && second)
            {
                phones ph2 = phoneList[1];
                ph2.number          = phone2;
                ph2.sharehaId       = shreha2;
                DB.Entry(ph2).State = EntityState.Modified;
                DB.SaveChanges();
            }
            else if (phone2 != "" && !second)
            {
                phones ph2 = new phones();
                ph2.clientId  = cId;
                ph2.number    = phone2;
                ph2.sharehaId = shreha2;
                DB.phones.Add(ph2);
                DB.SaveChanges();
            }

            if (phone3 != "" && third)
            {
                phones ph3 = phoneList[2];
                ph3.number          = phone3;
                ph3.sharehaId       = shreha3;
                DB.Entry(ph3).State = EntityState.Modified;
                DB.SaveChanges();
            }
            else if (phone3 != "" && !third)
            {
                phones ph3 = new phones();
                ph3.clientId  = cId;
                ph3.number    = phone3;
                ph3.sharehaId = shreha3;
                DB.phones.Add(ph3);
                DB.SaveChanges();
            }
        }
Exemple #7
0
        /// <summary>
        /// Gets the nav person.
        /// </summary>
        /// <param name="xmlDoc">The XML document.</param>
        /// <returns></returns>
        public static List <person> GetNAVPerson(XDocument xmlDoc)
        {
            List <person> personObj = new List <person>();
            //Fetch the elements
            IEnumerable <XElement> xelementList = xmlDoc.Descendants(Constants.PersonNode);

            //TODO: multiple person
            if (xelementList != null)
            {
                //Read the element value into person object
                personObj = (from b in xelementList
                             select new person
                {
                    personGuid = b.Element(Constants.PersonGuid) != null ? b.Element(Constants.PersonGuid).Value : null,
                    masterGuid = b.Element(Constants.MasterGuid) != null ? b.Element(Constants.MasterGuid).Value : null,
                    personId = b.Element(Constants.PersonId) != null ? b.Element(Constants.PersonId).Value : null,
                    firstName = b.Element(Constants.FirstName) != null ? b.Element(Constants.FirstName).Value : null,
                    lastName = b.Element(Constants.LastName) != null ? b.Element(Constants.LastName).Value : null,
                    title = b.Element(Constants.Title) != null ? b.Element(Constants.Title).Value : null,
                    messageCreatedDate = b.Attribute(Constants.MessageCreatedDate) != null ? b.Attribute(Constants.MessageCreatedDate).Value : null,
                    messageType = b.Attribute(Constants.MessageType) != null ? b.Attribute(Constants.MessageType).Value : null,
                    sender = b.Attribute(Constants.Sender) != null ? b.Attribute(Constants.Sender).Value : null,
                    originator = b.Attribute(Constants.Originator) != null ? b.Attribute(Constants.Originator).Value : null,
                }).ToList();

                foreach (person personData in personObj)
                {
                    //this is done as the person xml sent from person service do not have a value for originator. A work around for empty originator from person service
                    if (string.IsNullOrEmpty(personData.originator))
                    {
                        personData.originator = ConfigurationManager.AppSettings[Constants.DefaultOriginator];
                    }
                    //generate list of emails, phones and addresses
                    List <emails>    emailList   = new List <emails>();
                    List <addresses> addressList = new List <addresses>();
                    List <phones>    phoneList   = new List <phones>();

                    //Fetch the emails node content
                    IEnumerable <XElement> emailsElementList = xelementList.Elements(Constants.Emails);
                    if (emailsElementList != null && emailsElementList.Count() > 0)
                    {
                        //Fetch the email node from the emails element list
                        IEnumerable <XElement> emailElement = emailsElementList.Elements(Constants.Email);
                        if (emailElement != null && emailElement.Count() > 0)
                        {
                            //Read the Type and address of each email into the emails list
                            foreach (XElement email in emailElement)
                            {
                                email        mail       = new email();
                                List <email> emailsList = new List <email>();
                                emails       emails     = new emails();

                                mail.type = email.Attribute(Constants.Type) != null?email.Attribute(Constants.Type).Value : null;

                                mail.address = email.Attribute(Constants.Address) != null?email.Attribute(Constants.Address).Value : null;

                                emailsList.Add(mail);
                                emails.email = emailsList.ToArray();
                                emailList.Add(emails);
                            }
                            emails[] emailArray = emailList.ToArray();
                            personData.emails = emailArray;
                        }
                    }

                    //Fetch the addresses node content
                    IEnumerable <XElement> addressesElementList = xelementList.Elements(Constants.Addresses);
                    if (addressesElementList != null && addressesElementList.Count() > 0)
                    {
                        //Fetch the address node from the addresses element list
                        IEnumerable <XElement> addressElement = addressesElementList.Elements(Constants.Address);
                        if (addressElement != null && addressElement.Count() > 0)
                        {
                            foreach (XElement addressDetail in addressElement)
                            {
                                address        addressObj    = new address();
                                List <address> addressesList = new List <address>();
                                addresses      addressesObj  = new addresses();

                                addressObj.number = addressDetail.Attribute(Constants.Number) != null?addressDetail.Attribute(Constants.Number).Value : null;

                                addressObj.id = addressDetail.Attribute(Constants.ID) != null?addressDetail.Attribute(Constants.ID).Value : null;

                                addressObj.type = addressDetail.Attribute(Constants.Type) != null?addressDetail.Attribute(Constants.Type).Value : null;

                                addressObj.shipToName = addressDetail.Attribute(Constants.ShipToName) != null?addressDetail.Attribute(Constants.ShipToName).Value : null;

                                addressObj.isPrimary = addressDetail.Attribute(Constants.IsPrimary) != null?addressDetail.Attribute(Constants.IsPrimary).Value : null;

                                addressObj.companyName = addressDetail.Element(Constants.CompanyName) != null?addressDetail.Element(Constants.CompanyName).Value : null;

                                addressObj.country = addressDetail.Element(Constants.Country) != null?addressDetail.Element(Constants.Country).Value : null;

                                addressObj.city = addressDetail.Element(Constants.City) != null?addressDetail.Element(Constants.City).Value : null;

                                addressObj.line1 = addressDetail.Element(Constants.Line1) != null?addressDetail.Element(Constants.Line1).Value : null;

                                addressObj.line2 = addressDetail.Element(Constants.Line2) != null?addressDetail.Element(Constants.Line2).Value : null;

                                addressObj.line3 = addressDetail.Element(Constants.Line3) != null?addressDetail.Element(Constants.Line3).Value : null;

                                addressObj.regionCode = addressDetail.Element(Constants.RegionCode) != null?addressDetail.Element(Constants.RegionCode).Value : null;

                                addressObj.postalCode = addressDetail.Element(Constants.PostalCode) != null?addressDetail.Element(Constants.PostalCode).Value : null;

                                addressesList.Add(addressObj);
                                addressesObj.address = addressesList.ToArray();

                                addressList.Add(addressesObj);
                            }
                            addresses[] addressArray = addressList.ToArray();
                            personData.addresses = addressArray;
                        }
                    }
                    //Fetch the phones node content
                    IEnumerable <XElement> phonesElementList = xelementList.Elements(Constants.Phones);
                    if (phonesElementList != null && phonesElementList.Count() > 0)
                    {
                        //Fetch the phone node from the phones element list
                        IEnumerable <XElement> phoneElement = phonesElementList.Elements(Constants.Phone);
                        if (phoneElement != null && phoneElement.Count() > 0)
                        {
                            foreach (XElement phoneDetail in phoneElement)
                            {
                                phone        phoneObj   = new phone();
                                phones       phonesObj  = new phones();
                                List <phone> phonesList = new List <phone>();

                                phoneObj.number = phoneDetail.Attribute(Constants.Number).Value;
                                phoneObj.type   = phoneDetail.Attribute(Constants.Type).Value;


                                phonesList.Add(phoneObj);
                                phonesObj.phone = phonesList.ToArray();
                                phoneList.Add(phonesObj);
                            }
                            phones[] phoneArray = phoneList.ToArray();
                            personData.phones = phoneArray;
                        }
                    }
                }
            }
            return(personObj);
        }