Example #1
0
        public static List <UserData> GetUsers()
        {
            List <UserData> users = new List <UserData>();

            try
            {
                XElement userXml = RemoteAccess.GetXmlFromServer("users.xml");

                IEnumerable <XElement> userElements = userXml.Elements("user");

                foreach (XElement userElement in userElements)
                {
                    UserData user = new UserData();
                    user.LoginId   = userElement.GetAttribute("loginid");
                    user.Password  = userElement.GetAttribute("password");
                    user.FirstName = userElement.GetAttribute("firstname");
                    user.LastName  = userElement.GetAttribute("lastname");
                    user.Address   = userElement.GetAttribute("address");
                    user.Phone     = userElement.GetAttribute("phone");
                }
            }
            catch
            {
            }

            return(users);
        }
Example #2
0
        public static List <CompanyData> GetCompanies()
        {
            List <CompanyData> companies = new List <CompanyData>();

            try
            {
                XElement companiesXml = RemoteAccess.GetXmlFromServer("companies.xml");

                IEnumerable <XElement> companiesElements = companiesXml.Elements("company");

                foreach (XElement companyElement in companiesElements)
                {
                    CompanyData company = new CompanyData();
                    company.Deserialize(companyElement);
                    if (string.IsNullOrEmpty(company.ClassName))
                    {
                        company.ClassName = "BaseCalculator";
                    }

                    companies.Add(company);
                }
            }
            catch
            {
            }

            return(companies);
        }
Example #3
0
 public static bool DoesUserExists(string loginId)
 {
     try
     {
         XElement userMetaData = RemoteAccess.GetXmlFromServer("users", $"{loginId}.xml");
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #4
0
        public static CompanyData GetCompanyData(string companyCode)
        {
            try
            {
                XElement companymetadata = RemoteAccess.GetXmlFromServer("companies", $"{companyCode}.xml");

                CompanyData companyData = new CompanyData();
                companyData.Deserialize(companymetadata);

                return(companyData);
            }
            catch
            {
                return(null);
            }
        }
Example #5
0
        public static UserData GetUserData(string loginId)
        {
            try
            {
                XElement userMetaData = RemoteAccess.GetXmlFromServer("users", $"{loginId}.xml");

                UserData user = new UserData();
                user.Deserialize(userMetaData);

                return(user);
            }
            catch
            {
                return(null);
            }
        }
Example #6
0
        public static bool UpdateCompanyData(CompanyData companyData)
        {
            try
            {
                XElement xmlCompanyData = companyData.Serialize();
                string   filePath       = Path.Combine(CommonFunctions.GetTempPath(), $"{companyData.Code}.xml");
                xmlCompanyData.Save(filePath);

                RemoteAccess.PutToServer("companies", filePath);

                XElement companies;
                try
                {
                    companies = RemoteAccess.GetXmlFromServer("companies.xml");
                }
                catch
                {
                    companies = new XElement("companies");
                }

                XElement company = companies.Elements().FirstOrDefault(x => x.GetAttribute("code").IsStringEqual(companyData.Code));
                if (company != null)
                {
                    company.Remove();
                }

                XElement factorSheet = xmlCompanyData.Element("factorsheet");
                if (factorSheet != null)
                {
                    factorSheet.Remove();
                }

                companies.Add(xmlCompanyData);

                filePath = Path.Combine(CommonFunctions.GetTempPath(), "companies.xml");
                companies.Save(filePath);

                RemoteAccess.PutToServer(filePath);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #7
0
        public static bool UpdateUserData(UserData userData)
        {
            try
            {
                XElement xmlUserData = userData.Serialize();
                string   filePath    = Path.Combine(CommonFunctions.GetTempPath(), $"{userData.LoginId}.xml");
                xmlUserData.Save(filePath);

                RemoteAccess.PutToServer("users", filePath);

                XElement users;
                try
                {
                    users = RemoteAccess.GetXmlFromServer("users.xml");
                }
                catch
                {
                    users = new XElement("users");
                }

                XElement user = users.Elements().FirstOrDefault(x => x.GetAttribute("loginid").IsStringEqual(userData.LoginId));
                if (user != null)
                {
                    user.Remove();
                }

                users.Add(xmlUserData);

                filePath = Path.Combine(CommonFunctions.GetTempPath(), "users.xml");
                users.Save(filePath);

                RemoteAccess.PutToServer(filePath);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #8
0
        public static XElement GetUsersXml()
        {
            XElement usersXml = RemoteAccess.GetXmlFromServer("users.xml");

            return(usersXml);
        }
Example #9
0
        public static XElement GetCompaniesXml()
        {
            XElement companiesXml = RemoteAccess.GetXmlFromServer("companies.xml");

            return(companiesXml);
        }