コード例 #1
0
ファイル: Tempworks.cs プロジェクト: employnet/EmployNetTools
        public static bool AddCustomerProc(SqlConnection con, DataLayer.Models.TempWorks.Customer model, Int64 customerId = 0, bool replace = false)
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection = con;
                cmd.Parameters.Add(new SqlParameter("@override", replace == false ? 0 : 1));
                cmd.Parameters.Add(new SqlParameter("@customerId", model.CustomerId));
                cmd.Parameters.Add(new SqlParameter("@customerName", model.CustomerName));
                cmd.Parameters.Add(new SqlParameter("@departmentName", model.DepartmentName));
                cmd.Parameters.Add(new SqlParameter("@parentCustomerId", customerId != 0 ? customerId : model.ParentCustomerId));
                cmd.Parameters.Add(new SqlParameter("@rootCustomerId", model.RootCustomerId));
                cmd.Parameters.Add(new SqlParameter("@branchId", model.BranchId));
                cmd.Parameters.Add(new SqlParameter("@branchName", model.BranchName));
                cmd.Parameters.Add(new SqlParameter("@customerStatusId", model.CustomerStatusId));
                cmd.Parameters.Add(new SqlParameter("@customerStatus", model.CustomerStatus));
                cmd.Parameters.Add(new SqlParameter("@website", String.IsNullOrEmpty(model.Website) ? "" : model.Website));
                cmd.Parameters.Add(new SqlParameter("@isActive", model.IsActive));
                cmd.Parameters.Add(new SqlParameter("@dateActivated", DateTime.Parse(String.IsNullOrEmpty(model.DateActivated) ? "01/01/1900" : model.DateActivated)));
                cmd.Parameters.Add(new SqlParameter("@worksiteId", model.WorksiteId));
                cmd.Parameters.Add(new SqlParameter("@worksiteName", model.WorksiteName));

                cmd.Parameters.Add(new SqlParameter("@note", model.Note));

                cmd.Parameters.Add(new SqlParameter("@addressId", AddAddressProc(con, model.Address)));
                cmd.Parameters.Add(new SqlParameter("@billingAddressId", AddAddressProc(con, model.BillingAddress)));
                cmd.Parameters.Add(new SqlParameter("@worksiteAddressId", AddAddressProc(con, model.WorksiteAddress)));
                cmd.Parameters.Add(new SqlParameter("@isKronosTime", 0));

                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.CommandText = "prAddCustomer";
                cmd.ExecuteNonQuery();
            }
            return(true);
        }
コード例 #2
0
ファイル: Tempworks.cs プロジェクト: employnet/EmployNetTools
        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);
        }