//Dùng để thao tác đơn lẻ với S35
        public bool SaveInvoiceS35(List <InvoiceS35> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = InvoiceS35DAO.GetInvoiceS35SEQ();
                    foreach (InvoiceS35 data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.InvoiceS35ID = GenerateID.InvoiceS35ID(seq);
                            this.InvoiceS35DAO.InsertInvoiceS35(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.InvoiceS35DAO.UpdateInvoiceS35(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.InvoiceS35DAO.DeleteInvoiceS35(data);
                            //Khi delete InvoiceS35 thì DB sẽ tự delete InvoiceS35Detail
                            break;
                        }
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
 public InvoiceS35Controller()
 {
     this.Context         = new BSContext();
     this.InvoiceS35DAO   = new InvoiceS35DAO(this.Context);
     this.InvoiceS35Logic = new InvoiceS35Logic(this.Context);
 }
        public bool SaveInvoiceS35Full(InvoiceS35 data, List <InvoiceS35Detail> detailData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq       = InvoiceS35DAO.GetInvoiceS35SEQ();
                    long seqdetail = InvoiceS35DetailDAO.GetInvoiceS35DetailSEQ();
                    switch (data.Status)
                    {
                    // Thêm S35 mới thì sẽ thực hiện thêm Detail mới nếu ListDetail có giá trị
                    case ModifyMode.Insert:
                        seq++;
                        data.InvoiceS35ID = GenerateID.InvoiceS35ID(seq);
                        this.InvoiceS35DAO.InsertInvoiceS35(data);
                        if (detailData.Count > 0)
                        {
                            //thêm InvoiceS35Detail
                            #region insert InvoiceS35Detail
                            foreach (InvoiceS35Detail invoiceS35Detail in detailData)
                            {
                                if (string.IsNullOrEmpty(invoiceS35Detail.InvoiceS35DetailID))
                                {
                                    seqdetail++;
                                    invoiceS35Detail.InvoiceS35DetailID = GenerateID.InvoiceS35DetailID(seqdetail);
                                    invoiceS35Detail.InvoiceS35ID       = data.InvoiceS35ID;
                                    invoiceS35Detail.CompanyID          = data.CompanyID;
                                    this.InvoiceS35DetailDAO.InsertInvoiceS35Detail(invoiceS35Detail);
                                }
                            }
                            #endregion insert InvoiceS35Detail
                        }
                        break;

                    //Khi update S35 thì sẽ thực hiện update S35, Thêm mới hoặc update S35 Detail
                    case ModifyMode.Update:
                        this.InvoiceS35DAO.UpdateInvoiceS35(data);
                        if (detailData.Count > 0)
                        {
                            foreach (InvoiceS35Detail invoiceS35Detail in detailData)
                            {
                                //thực hiện nhiệm vụ update với các chi tiết S35 đã thuộc S35
                                if (invoiceS35Detail.Status == ModifyMode.Update)
                                {
                                    #region Update dataDetail
                                    if (!string.IsNullOrEmpty(invoiceS35Detail.InvoiceS35DetailID))
                                    {
                                        this.InvoiceS35DetailDAO.UpdateInvoiceS35Detail(invoiceS35Detail);
                                    }
                                    #endregion Update dataDetail
                                }
                                else if (invoiceS35Detail.Status == ModifyMode.Insert)
                                {
                                    //thêm mới InvoiceS35Detail vào S35
                                    #region insert InvoiceS35Detail khi thêm detail mới cho S35 đã có sẵn
                                    if (string.IsNullOrEmpty(invoiceS35Detail.InvoiceS35DetailID))
                                    {
                                        seqdetail++;
                                        invoiceS35Detail.InvoiceS35DetailID = GenerateID.InvoiceS35DetailID(seqdetail);
                                        invoiceS35Detail.InvoiceS35ID       = data.InvoiceS35ID;
                                        invoiceS35Detail.CompanyID          = data.CompanyID;
                                        this.InvoiceS35DetailDAO.InsertInvoiceS35Detail(invoiceS35Detail);
                                    }
                                    #endregion insert InvoiceS35Detail khi thêm detail mới cho S35 đã có sẵn
                                }
                            }
                        }
                        break;

                    // Delete
                    case ModifyMode.Delete:
                        this.InvoiceS35DAO.DeleteInvoiceS35(data);
                        //Khi delete InvoiceS35 thì DB sẽ tự delete InvoiceS35Detail
                        break;

                    default:
                        //Khi InvoiceS35 không thực thêm, xóa, sửa thì có thể sẽ có thay đổi giá trị S35Detail
                        if (detailData.Count > 0)
                        {
                            foreach (InvoiceS35Detail invoiceS35Detail in detailData)
                            {
                                //thực hiện nhiệm vụ update với các chi tiết S35 đã thuộc S35
                                if (invoiceS35Detail.Status == ModifyMode.Update)
                                {
                                    #region Update dataDetail
                                    if (!string.IsNullOrEmpty(invoiceS35Detail.InvoiceS35DetailID))
                                    {
                                        this.InvoiceS35DetailDAO.UpdateInvoiceS35Detail(invoiceS35Detail);
                                    }
                                    #endregion Update dataDetail
                                }
                                else if (invoiceS35Detail.Status == ModifyMode.Insert)
                                {
                                    //thêm mới InvoiceS35Detail vào S35
                                    #region insert InvoiceS35Detail khi thêm detail mới cho S35 đã có sẵn
                                    if (string.IsNullOrEmpty(invoiceS35Detail.InvoiceS35DetailID))
                                    {
                                        seqdetail++;
                                        invoiceS35Detail.InvoiceS35DetailID = GenerateID.InvoiceS35DetailID(seqdetail);
                                        invoiceS35Detail.InvoiceS35ID       = data.InvoiceS35ID;
                                        invoiceS35Detail.CompanyID          = data.CompanyID;

                                        this.InvoiceS35DetailDAO.InsertInvoiceS35Detail(invoiceS35Detail);
                                    }
                                    #endregion insert InvoiceS35Detail khi thêm detail mới cho S35 đã có sẵn
                                }
                            }
                        }
                        break;
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }