Esempio n. 1
0
        public static bool AddBranch(DataSurfContext context, Models.TempWorks.Branch model)
        {
            Models.TempWorksDB.Branch result = context.Branch.FirstOrDefault(result => result.BranchId == model.BranchId);
            bool addRec = false;

            if (result == null)
            {
                addRec = true;
                result = new Models.TempWorksDB.Branch();
            }

            result.BranchId       = model.BranchId;
            result.BranchFullName = model.BranchFullName;
            result.BranchName     = model.BranchName;
            result.PhoneNumber    = model.PhoneNumber;
            result.IsActive       = model.IsActive;
            result.HierId         = model.HierId;
            result.Employer       = model.Employer;
            result.EmployerId     = model.EmployerId;
            result.EmailAddress   = model.EmailAddress;
            Models.TempWorksDB.Address add = new Models.TempWorksDB.Address()
            {
                Street1      = model.Address.Street1,
                Street2      = model.Address.Street2,
                PostalCode   = model.Address.PostalCode,
                Country      = model.Address.Country,
                Municipality = model.Address.Municipality,
                Region       = model.Address.Region,
                AttentionTo  = model.Address.AttentionTo
            };

            result.AddressId = AddAddress(context, add);

            if (addRec)
            {
                context.Branch.Add(result);
            }
            else
            {
                context.Branch.Update(result);
            }

            context.SaveChanges();


            return(true);
        }
Esempio n. 2
0
        public static int AddAddress(DataSurfContext context, DataLayer.Models.TempWorksDB.Address model)
        {
            if (String.IsNullOrEmpty(model.Street1))
            {
                return(0);
            }

            Models.TempWorksDB.Address result = context.Address.FirstOrDefault(result => result.Street1 == model.Street1 && result.PostalCode == model.PostalCode);
            bool addRec = false;

            if (result == null)
            {
                addRec = true;
                result = new Models.TempWorksDB.Address();
            }
            result.Street1      = model.Street1;
            result.Street2      = model.Street2;
            result.PostalCode   = model.PostalCode;
            result.Region       = model.Region;
            result.Municipality = model.Municipality;
            result.AttentionTo  = model.AttentionTo;
            result.Country      = model.Country;

            if (addRec)
            {
                context.Address.Add(result);
            }
            else
            {
                context.Address.Update(result);
            }

            context.SaveChanges();

            return(result.AddressId);
        }
Esempio n. 3
0
        public static bool AddCustomer(DataSurfContext context, DataLayer.Models.TempWorks.Customer model)
        {
            Models.TempWorksDB.Customer result = context.Customer.FirstOrDefault(results => results.CustomerId == model.CustomerId);
            bool addRec = false;

            if (result == null)
            {
                addRec = true;
                result = new Models.TempWorksDB.Customer();
            }
            result.CustomerId       = model.CustomerId;
            result.CustomerName     = model.CustomerName;
            result.CustomerStatus   = model.CustomerStatus;
            result.CustomerStatusId = model.CustomerStatusId;
            result.DateActivated    = DateTime.Parse(model.DateActivated);
            result.DepartmentName   = model.DepartmentName;
            //result.ParentCustomerId = model.ParentCustomerId;
            result.RootCustomerId = model.RootCustomerId;


            Models.TempWorksDB.Address add = new Models.TempWorksDB.Address();
            add.Street1      = model.BillingAddress.Street1;
            add.Street2      = model.BillingAddress.Street2;
            add.PostalCode   = model.BillingAddress.PostalCode;
            add.Municipality = model.BillingAddress.Municipality;
            add.Region       = model.BillingAddress.Region;
            add.AttentionTo  = model.BillingAddress.AttentionTo;
            add.Country      = model.BillingAddress.Country;

            result.BillingAddressID = AddAddress(context, add);

            add.Street1      = model.WorksiteAddress.Street1;
            add.Street2      = model.WorksiteAddress.Street2;
            add.Municipality = model.WorksiteAddress.Municipality;
            add.PostalCode   = model.WorksiteAddress.PostalCode;
            add.Region       = model.WorksiteAddress.Region;
            add.AttentionTo  = model.WorksiteAddress.AttentionTo;
            add.Country      = model.WorksiteAddress.Country;

            result.WorksiteAddressID = AddAddress(context, add);


            result.BranchId   = model.BranchId;
            result.BranchName = model.BranchName;



            if (addRec)
            {
                context.Customer.Add(result);
            }
            else
            {
                context.Customer.Update(result);
            }

            context.SaveChanges();


            return(true);
        }