コード例 #1
0
        public int AddCompany(PharmaBusinessObjects.Master.CompanyMaster company)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                List <string> companyCodeList = context.CompanyMaster.Select(p => p.CompanyCode).ToList();

                int maxCompanyCode = companyCodeList.Count > 0 ? companyCodeList.Max(p => Convert.ToInt32(p)) + 1 : 1;

                var companyCode = maxCompanyCode.ToString().PadLeft(6, '0');

                Entity.CompanyMaster table = new Entity.CompanyMaster()
                {
                    CompanyCode             = companyCode,
                    Status                  = company.Status,
                    StockSummaryRequired    = company.StockSummaryRequired,
                    IsDirect                = company.IsDirect,
                    OrderPreferenceRating   = company.OrderPreferenceRating,
                    BillingPreferenceRating = company.BillingPreferenceRating,
                    CompanyName             = company.CompanyName,
                    CreatedBy               = this.LoggedInUser.Username,
                    CreatedOn               = System.DateTime.Now
                };

                context.CompanyMaster.Add(table);

                if (context.SaveChanges() > 0)
                {
                    return(table.CompanyId);
                }
                else
                {
                    return(0);
                }
            }
        }
コード例 #2
0
        public int UpdateCompany(PharmaBusinessObjects.Master.CompanyMaster company)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                var companyMaster = context.CompanyMaster.FirstOrDefault(p => p.CompanyId == company.CompanyId);

                if (companyMaster != null)
                {
                    companyMaster.Status = company.Status;
                    companyMaster.StockSummaryRequired    = company.StockSummaryRequired;
                    companyMaster.IsDirect                = company.IsDirect;
                    companyMaster.OrderPreferenceRating   = company.OrderPreferenceRating;
                    companyMaster.BillingPreferenceRating = company.BillingPreferenceRating;
                    companyMaster.CompanyName             = company.CompanyName;
                    companyMaster.ModifiedBy              = this.LoggedInUser.Username;
                    companyMaster.ModifiedOn              = System.DateTime.Now;
                }

                return(context.SaveChanges());
            }
        }