public bool EditCycle(EditCycle cycleUpdate, int pfNumber) { TransactionScope scope = new TransactionScope(); try { if (this.pcRules.IsPfNumberValid(pfNumber)) { using (scope) { PerformanceReviewCycle cycle = new PerformanceReviewCycle { Id = cycleUpdate.Id, Year = cycleUpdate.Year, Period = cycleUpdate.Period, StartDate = cycleUpdate.StartDate, CloseDate = cycleUpdate.CloseDate, Status = cycleUpdate.Status }; this.db.Entry(cycle).State = EntityState.Modified; this.db.SaveChanges(); scope.Complete(); } return true; } else { scope.Dispose(); return false; } } catch (DataException) { scope.Dispose(); return false; } catch (TransactionAbortedException) { scope.Dispose(); return false; } catch (TransactionException) { scope.Dispose(); return false; } catch (Exception) { scope.Dispose(); return false; } }
/// <summary> /// Add new cycle to the repository. /// </summary> /// <param name="newCycle">The new cycle to be added.</param> /// <param name="pfNumber">The pf number of user.</param> /// <returns> /// Flag indicating whether the operation was successful. /// </returns> public bool NewCycle(AddCycle newCycle, int pfNumber) { if (this.pcRules.IsPfNumberValid(pfNumber)) { if (this.pcRules.IsNewCycleDataValid(newCycle) != null) { PerformanceReviewCycle cycle = new PerformanceReviewCycle { Year = newCycle.Year, Period = newCycle.Period, Status = "Draft", StartDate = newCycle.StartDate, CloseDate = newCycle.CloseDate }; this.db.PerformanceReviewCycles.Add(cycle); this.db.SaveChanges(); return true; } else { return false; } } else { return false; } }