예제 #1
0
        private void UpdateApplicationRoles(contactPerson contactPerson, DALPortalDataContext dc)
        {
            if (!contactPerson.isWebContact)
            {
                // Delete all roles
                var userRoles = dc.userRoles.Where(c => c.userId.Equals(contactPerson.userId));
                dc.userRoles.DeleteAllOnSubmit(userRoles);

                dc.SubmitChanges();
                return;
            }

            // Add CERT_USER role
            if (contactPerson.TMP_PortalAccess == "01" || contactPerson.TMP_PortalAccess == "04")
                if (!dc.userRoles.Any(c => c.userId.Equals(contactPerson.userId) && c.roleCode.Equals("CERT_USER")))
                    dc.userRoles.InsertOnSubmit(new userRole() { userId = contactPerson.userId.Value, roleCode = "CERT_USER" });

            // Add DOP_USER role
            if (contactPerson.TMP_PortalAccess == "03" || contactPerson.TMP_PortalAccess == "04")
                if (!dc.userRoles.Any(c => c.userId.Equals(contactPerson.userId) && c.roleCode.Equals("DOP_USER")))
                    dc.userRoles.InsertOnSubmit(new userRole() { userId = contactPerson.userId.Value, roleCode = "DOP_USER" });

            if (contactPerson.TMP_PortalAccess == "01")
            {
                // Delete DOP_USER role
                var userRoles = dc.userRoles.Where(c => c.userId.Equals(contactPerson.userId) && c.roleCode.Equals("DOP_USER"));
                dc.userRoles.DeleteAllOnSubmit(userRoles);
            }

            if (contactPerson.TMP_PortalAccess == "03")
            {
                // Delete CERT_USER role
                var userRoles = dc.userRoles.Where(c => c.userId.Equals(contactPerson.userId) && c.roleCode.Equals("CERT_USER"));
                dc.userRoles.DeleteAllOnSubmit(userRoles);
            }

            if (contactPerson.TMP_PortalAccess == null)
            {
                // Delete all roles
                var userRoles = dc.userRoles.Where(c => c.userId.Equals(contactPerson.userId));
                dc.userRoles.DeleteAllOnSubmit(userRoles);
            }

            dc.SubmitChanges();
        }
예제 #2
0
        public static Boolean ProcessCustomer(string fileContent, out businessPartner businessPartner, out String outCompanyCode)
        {
            businessPartner = new businessPartner();

            DALPortalDataContext dc = new DALPortalDataContext();
            Boolean update;
            String companyCode = String.Empty;
            outCompanyCode = String.Empty;

            try
            {
                XDocument xmldoc = XDocument.Parse(fileContent);
                XElement docTypeElement = xmldoc.Element("DEBMAS03");
                XElement iDocElement = docTypeElement.Element("IDOC");
                var customerHeaderElement = iDocElement.Element("E1KNA1M");
                //Int32 CardCode;

                // Remove unused elements
                iDocElement.Element("EDI_DC40").Remove();

                // BpCode, remove leading zero's from Cardcode
                String bpCode = Convert.ToInt32(customerHeaderElement.Element("KUNNR").Value).ToString();
                String sectionCode = customerHeaderElement.Element("E1KNVVM").Element("VKORG").Value;

                companyCode = CompanyClass.GetCompanyBasedOnSection(sectionCode, dc);
                outCompanyCode = companyCode;

                // Check if bp Already exists
                businessPartner = BusinessPartnerClass.GetBusinessPartner(bpCode, companyCode, dc);
                if (businessPartner == null)
                {
                    businessPartner = new businessPartner();
                    update = false;
                }
                else
                {
                    update = true;
                }

                if (!update)
                {
                    String companyGroupCode = dc.companyGroupForBps.Where(c => c.companyCode.Equals(companyCode)).Select(c => c.companyGroupCode).FirstOrDefault();

                    if (String.IsNullOrEmpty(companyGroupCode))
                        businessPartner.companyCode = companyCode;
                    else
                        businessPartner.companyGroupCode = companyGroupCode;
                }

                // Mapp customer header data
                businessPartner.bpCode = bpCode;
                businessPartner.bpType = 'C';
                businessPartner.bpName = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("NAME1")).FirstOrDefault().Value;
                businessPartner.address = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("STRAS")).FirstOrDefault().Value;

                if (customerHeaderElement.Elements().Any(c => c.Name.ToString().Equals("TELF1")))
                    businessPartner.telephone = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("TELF1")).FirstOrDefault().Value;

                if(customerHeaderElement.Elements().Any(c => c.Name.ToString().Equals("TELFX")))
                    businessPartner.fax = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("TELFX")).FirstOrDefault().Value;

                businessPartner.countryCode = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("LAND1")).FirstOrDefault().Value;
                businessPartner.languageCode = customerHeaderElement.Elements().Where(c => c.Name.ToString().Equals("SPRAS_ISO")).FirstOrDefault().Value;

                // Mapp contactperson data
                foreach (var contactpersonElement in customerHeaderElement.Elements("E1KNVKM").ToList())
                {
                    contactPerson contact;

                    // Contact Id
                    String contactPersonCode = Convert.ToInt32(contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("PARNR")).FirstOrDefault().Value).ToString();
                    Boolean newContact = false;

                    if (update && businessPartner.contactPersons.Any(c => c.contactPersonCode.Equals(contactPersonCode)))
                    {
                        contact = businessPartner.contactPersons.Where(c => c.contactPersonCode.Equals(contactPersonCode)).FirstOrDefault();
                    }
                    else
                    {
                        contact = new contactPerson();
                        contact.contactPersonCode = contactPersonCode;
                        newContact = true;
                    }

                    // Email
                    var emailAddress = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("PARAU")).FirstOrDefault();
                    if (emailAddress != null)
                        contact.eMail = emailAddress.Value.ToLower();

                    // Title
                    var title = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("ANRED")).FirstOrDefault();
                    if (title != null)
                        contact.title = title.Value;

                    // FirstName
                    var firstName = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("NAMEV")).FirstOrDefault();
                    if (firstName != null)
                        contact.firstName = firstName.Value;

                    // LastName
                    var lastName = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("NAME1")).FirstOrDefault();
                    if (lastName != null)
                        contact.lastName = lastName.Value;

                    // WebUser
                    var webUserType = contactpersonElement.Elements().Where(c => c.Name.ToString().Equals("AKVER")).FirstOrDefault();
                    if (webUserType != null)
                    {
                        contact.isWebContact = (webUserType.Value == "02") ? false : true;
                        contact.TMP_PortalAccess = webUserType.Value;
                    }

                    // Add CardCode to contactperson
                    if (newContact)
                        businessPartner.contactPersons.Add(contact);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(String.Format("Error converting customer {0} for company {1} from SAP ECC6 XML format. Error: {2}", businessPartner.bpCode, companyCode, ex.Message), "MapCustomerFromECC6");
                return false;
            }

            if (update)
            {
                try
                {
                    dc.SubmitChanges();
                    Trace.WriteLine(String.Format("Updating Customer {0} for company {1} Successfull.", businessPartner.bpCode, companyCode), "MapCustomerFromECC6");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(String.Format("Error Updating Customer {0} for company {1}. Error: {2}", businessPartner.bpCode, companyCode, ex.Message), "MapCustomerFromECC6");
                    return false;
                }
            }
            else
            {
                try
                {
                    dc.businessPartners.InsertOnSubmit(businessPartner);
                    dc.SubmitChanges();
                    Trace.WriteLine(String.Format("Creating Customer {0} for company {1} Successfull.", businessPartner.bpCode, companyCode), "MapCustomerFromECC6");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(String.Format("Error Creating Customer {0} for company {1}. Error: {2}", businessPartner.bpCode, companyCode, ex.Message), "MapCustomerFromECC6");
                    return false;
                }
            }

            return true;
        }
예제 #3
0
 partial void DeletecontactPerson(contactPerson instance);
예제 #4
0
 partial void UpdatecontactPerson(contactPerson instance);
예제 #5
0
 partial void InsertcontactPerson(contactPerson instance);
예제 #6
0
		private void detach_contactPersons(contactPerson entity)
		{
			this.SendPropertyChanging();
			entity.businessPartner = null;
		}
예제 #7
0
		private void attach_contactPersons(contactPerson entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}