Ejemplo n.º 1
0
        public SavingResult DeleteRecord(long DeleteID)
        {
            SavingResult res = new SavingResult();

            using (dbVisionEntities db = new dbVisionEntities())
            {
                if (DeleteID != 0)
                {
                    tblPAYERelief RecordToDelete = db.tblPAYEReliefs.FirstOrDefault(r => r.PAYEReliefID == DeleteID);

                    if (RecordToDelete == null)
                    {
                        res.ValidationError = "Selected record not found. May be it has been deleted by another user over network.";
                        res.ExecutionResult = eExecutionResult.ValidationError;
                        return(res);
                    }
                    else
                    {
                        //db.tblPAYEReliefs.Remove(RecordToDelete);
                        byte RecordState_Deleted = (byte)eRecordState.Deleted;
                        RecordToDelete.rstate = RecordState_Deleted;
                        db.tblPAYEReliefs.Attach(RecordToDelete);
                        db.Entry(RecordToDelete).State = System.Data.Entity.EntityState.Modified;
                    }

                    try
                    {
                        db.SaveChanges();
                        res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                    }
                    catch (Exception ex)
                    {
                        CommonFunctions.GetFinalError(res, ex);
                    }
                }
            }
            return(res);
        }
Ejemplo n.º 2
0
        public SavingResult SaveNewRecord(PAYEReliefeViewModel ViewModel, DateTime WEDate)
        {
            SavingResult res = new SavingResult();

            //-- Perform Validation
            //res.ExecutionResult = eExecutionResult.ValidationError;
            //res.ValidationError = "Validation error message";
            //return res;

            tblPAYERelief SaveModel = null;

            //--
            using (dbVisionEntities db = new dbVisionEntities())
            {
                //tblPAYERelief SaveModel;
                if (String.IsNullOrWhiteSpace(ViewModel.PAYEReliefName))
                {
                    res.ValidationError = "Can not accept blank value. Please enter PAYE Relief Name.";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }
                else if (IsDuplicateRecord(ViewModel.PAYEReliefName, ViewModel.PAYEReliefID, db))
                {
                    res.ValidationError = "Can not accept duplicate value. The PAYE Relief Name is already exists.";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }

                if (ViewModel.PAYEReliefID != 0)
                {
                    SaveModel = db.tblPAYEReliefs.Find(ViewModel.PAYEReliefID);
                }

                tblPAYEReliefRate RateSaveModel = null;
                if (SaveModel == null) // New Entry
                {
                    SaveModel           = new tblPAYERelief();
                    SaveModel.CompanyID = CommonProperties.LoginInfo.LoggedInCompany.CompanyID;
                    SaveModel.rcuid     = Model.CommonProperties.LoginInfo.LoggedinUser.UserID;
                    SaveModel.rcdt      = DateTime.Now;
                    db.tblPAYEReliefs.Add(SaveModel);
                }
                else
                {
                    SaveModel.reuid = Model.CommonProperties.LoginInfo.LoggedinUser.UserID;
                    SaveModel.redt  = DateTime.Now;
                    db.tblPAYEReliefs.Attach(SaveModel);
                    db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified;

                    db.tblPAYEReliefRates.RemoveRange(db.tblPAYEReliefRates.Where(r => r.PAYEReliefID == SaveModel.PAYEReliefID && (WEDate == null || r.WEDate >= WEDate)));
                }

                SaveModel.PAYEReliefName = ViewModel.PAYEReliefName;
                SaveModel.Mandatory      = ViewModel.Mandatory == ePAYEReliefeMandatory.Yes;
                SaveModel.PAYEReliefType = (byte)ViewModel.PAYEReliefType;

                RateSaveModel = new tblPAYEReliefRate()
                {
                    WEDate       = WEDate,
                    MonthlyLimit = ViewModel.MonthlyLimit,
                    AnnualLimit  = ViewModel.AnnualLimit,

                    tblPAYERelief = SaveModel,
                    rcuid         = Model.CommonProperties.LoginInfo.LoggedinUser.UserID,
                    rcdt          = DateTime.Now,
                };
                db.tblPAYEReliefRates.Add(RateSaveModel);

                //--
                try
                {
                    db.SaveChanges();
                    //ViewModel.PAYEReliefID = SaveModel.PAYEReliefID;
                    res.PrimeKeyValue   = SaveModel.PAYEReliefID;
                    res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                }
                catch (Exception ex)
                {
                    CommonFunctions.GetFinalError(res, ex);
                }
            }
            return(res);
        }