public RotationInterval UpdateRotationInterval(int Id, RotationInterval NewRotationInterval) { try { var OldRotationInterval = db.RotationIntervals.SingleOrDefault(x => x.Id == Id); //iterate through all properties //except Id foreach (var property in NewRotationInterval .GetType() .GetProperties() .Where(x => x.Name != "Id")) { //get the value of the iterated property var value = property.GetValue(NewRotationInterval); if (value != null) { Type type = NewRotationInterval.GetType(); PropertyInfo propertyInfo = type.GetProperty(property.Name); propertyInfo.SetValue(OldRotationInterval, value, null); } } db.SaveChanges(); return(OldRotationInterval); } catch (Exception ex) { throw Utility.ThrowException(ex); } }
public RotationInterval AddRotationInterval(RotationInterval Value) { try { Value = db.RotationIntervals.Add(Value); db.SaveChanges(); return(GetRotationInterval(Value.Id)); } catch (Exception ex) { throw Utility.ThrowException(ex); } }
public _RotationInterval(RotationInterval Value) { try { TinyMapper.Bind <RotationInterval, _RotationInterval>(); TinyMapper.Map <RotationInterval, _RotationInterval>(Value, this); this.IntervalTypeName = Value.IntervalType.IntervalType1; } catch (Exception ex) { throw Utility.ThrowException(ex); } }
public void RotateChorelist(RotationInterval Rotation) { try { //bring choreusers list into memory var ChoreUsersStatic = db.ChoreUsers.Where(x => x.IsActive && x.ChoreListId == Rotation.ChoreListId).OrderBy(x => x.SortOrder).ToList(); var ChoresStatic = db.Chores.Where(x => x.IsActive && x.ChoreListId == Rotation.ChoreListId).OrderBy(x => x.SortOrder).ToList(); //update corresponding chore users foreach (var ChoreUser in db.ChoreUsers.Where(x => x.IsActive && x.ChoreListId == Rotation.ChoreListId)) { //set sort order between 1 and the max between chore count and chore users count ChoreUser.SortOrder = (ChoreUser.SortOrder++ % Math.Max(ChoreUsersStatic.Count, ChoresStatic.Count)) + 1; //set message chore (this can only be 1 or 0 in count) // if too many users, user sort order will be too high for chore // if too many chores, top users will not yet reach bottom of sort order var Chore = ChoresStatic.FirstOrDefault(x => x.SortOrder == ChoreUser.SortOrder); if (Chore != null) { //if message already exists for today, then don't send if (db.Messages.Count(x => ((DateTime)x.DateSent).Date == DateTime.Today && (int)x.ChoreId == Chore.Id) == 0) { //then create message for the chore-choreuser pair Message Message = new Message(); Message.ChoreUserId = ChoreUser.Id; Message.ChoreId = Chore.Id; Message.Phone = ChoreUser.Phone; Message.Email = ChoreUser.Email; Message.DateScheduled = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, Rotation.StartDate.Hour, Rotation.StartDate.Minute, 0); Message.IsVerified = ChoreUser.IsVerified; Message.IsSent = false; Message.IsComplete = false; db.Messages.Add(Message); } } } db.SaveChanges(); } catch (Exception ex) { throw Utility.ThrowException(ex); } }