Beispiel #1
0
        public bool UpdatePaymentType(PaymentTypeVM paymentTypeVM)
        {
            using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction())
            {
                try
                {
                    tblPaymentType paymentType = unitOfWork.TblPaymentTypeRepository.GetByID(paymentTypeVM.PaymentTypeID);
                    paymentType.PaymentType  = paymentTypeVM.PaymentTypeName;
                    paymentType.Description  = paymentTypeVM.Description;
                    paymentType.ModifiedDate = DateTime.Now;
                    paymentType.ModifiedBy   = paymentTypeVM.ModifiedBy;
                    unitOfWork.TblPaymentTypeRepository.Update(paymentType);
                    unitOfWork.Save();

                    //Complete the Transaction
                    dbTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    //Roll back the Transaction
                    dbTransaction.Rollback();
                    return(false);
                }
            }
        }
Beispiel #2
0
        public bool DeletePaymentType(int paymentTypeID)
        {
            using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction())
            {
                try
                {
                    tblPaymentType paymentType = unitOfWork.TblPaymentTypeRepository.GetByID(paymentTypeID);
                    unitOfWork.TblPaymentTypeRepository.Delete(paymentType);
                    unitOfWork.Save();

                    //Complete the Transaction
                    dbTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    //Roll back the Transaction
                    dbTransaction.Rollback();
                    return(false);
                }
            }
        }
        public void InsertPaymentType()
        {
            try
            {
                using (KungFuEntities2 entities = new KungFuEntities2())
                {
                    int   ihdnPKID      = int.Parse(hdnPKId.Value);
                    Int32 PaymentTypeID = 0;
                    if (ihdnPKID == 0)
                    {
                        PaymentTypeID = (from obj in entities.tblPaymentTypes
                                         where obj.PAYMENT_TYPE == txtPaymentType.Text
                                         select obj.PAYMENT_TYPE_ID).FirstOrDefault();
                    }
                    else
                    {
                        PaymentTypeID = (from obj in entities.tblPaymentTypes
                                         where (obj.PAYMENT_TYPE == txtPaymentType.Text && obj.PAYMENT_TYPE_ID != ihdnPKID)
                                         select obj.PAYMENT_TYPE_ID).FirstOrDefault();
                    }

                    if (PaymentTypeID == 0)
                    {
                        var objPaymentType = entities.tblPaymentTypes.Where(s => s.PAYMENT_TYPE_ID == ihdnPKID).OrderByDescending(s => s.PAYMENT_TYPE_ID).FirstOrDefault();
                        if (objPaymentType == null)
                        {
                            objPaymentType = new tblPaymentType();
                        }
                        objPaymentType.PAYMENT_TYPE              = txtPaymentType.Text;
                        objPaymentType.PAYMENT_TYPE_CREATED_BY   = entities.tblInstructors.AsEnumerable().FirstOrDefault().INSTRUCTOR_ID;
                        objPaymentType.PAYMENT_TYPE_CREATED_DATE = DateTime.Now;
                        objPaymentType.PAYMENT_TYPE_STATUS       = chkIsApprove.Checked;
                        objPaymentType.PAYMENT_TYPE_AMOUNT       = Convert.ToDecimal(txtAmount.Text);

                        if (objPaymentType.PAYMENT_TYPE_ID == 0)
                        {
                            entities.tblPaymentTypes.Add(objPaymentType);
                        }
                        else
                        {
                            objPaymentType.PAYMENT_TYPE_MODIFY_BY     = entities.tblInstructors.Select(x => x.INSTRUCTOR_ID).FirstOrDefault();
                            objPaymentType.PAYMENT_TYPE_MODIFIED_DATE = DateTime.Now;
                            entities.Entry(objPaymentType).State      = System.Data.Entity.EntityState.Modified;
                        }
                        entities.SaveChanges();

                        objPaymentType = null;
                        if (hdnPKId.Value != "0")
                        {
                            Response.Redirect("PaymentTypeList.aspx");
                        }


                        ResetControls();
                        divMessage.Visible  = true;
                        divErrorMsg.Visible = false;
                    }
                    else
                    {
                        divErrorMsg.Visible = true;
                        divMessage.Visible  = false;
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }