Пример #1
0
        public bool EditPajak(DataPajak oData)
        {
            methodName = "EditPajak";
            traceID    = 1;

            using (var uow = new UnitOfWork(AppConfig.Current.ContextName))
            {
                traceID = 2;
                var oDBData = uow.DataPajak.Get(oData.Id);
                if (oDBData != null)
                {
                    using (var trans = uow.BeginTransaction())
                    {
                        try
                        {
                            traceID = 3;
                            oDBData.MapFrom(oData);
                            uow.DataPajak.Update(oDBData);

                            traceID = 4;
                            ListDataPajak oDBListDataPajak = uow.ListDataPajak.SingleOrDefault(m => m.IdPajak == oData.Id);
                            if (oDBListDataPajak != null)
                            {
                                traceID = 5;
                                oDBListDataPajak.MapFrom(oData);

                                traceID = 6;
                                uow.ListDataPajak.Update(oDBListDataPajak);
                            }
                            else
                            {
                                traceID = 7;
                                ListDataPajak oNewListDataPajak = new ListDataPajak();
                                oNewListDataPajak.MapFrom(oData);

                                traceID = 8;
                                uow.ListDataPajak.Add(oNewListDataPajak);
                            }

                            traceID = 9;
                            uow.Save();
                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            throw new AppException(500, methodName, traceID, ex);
                        }
                    }
                }
            }

            return(true);
        }
Пример #2
0
        public int AddPajak(DataPajak oData)
        {
            methodName = "AddPajak";
            traceID    = 1;

            using (var uow = new UnitOfWork(AppConfig.Current.ContextName))
            {
                using (var trans = uow.BeginTransaction())
                {
                    try
                    {
                        traceID = 2;
                        DataPajak oNewDataPajak = new DataPajak();
                        oNewDataPajak.MapFrom(oData);
                        oNewDataPajak = uow.DataPajak.Add(oNewDataPajak);
                        uow.Save();

                        if (oNewDataPajak.Id > 0)
                        {
                            traceID  = 3;
                            oData.Id = oNewDataPajak.Id;
                            ListDataPajak oNewListDataPajak = new ListDataPajak();
                            oNewListDataPajak.MapFrom(oData);

                            traceID = 4;
                            oNewListDataPajak.IdPajak = oData.Id;
                            uow.ListDataPajak.Add(oNewListDataPajak);
                        }

                        traceID = 5;
                        uow.Save();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        throw new AppException(500, methodName, traceID, ex);
                    }
                }
            }

            return(oData.Id);
        }