public static TaskDTO StaticMapFrom(Task instance) { if (null == instance) { return null; } TaskDTO dto = new TaskDTO(); dto.MapFrom(instance); return dto; }
public Guid SaveTask(TaskDTO task) { Guid taskId = Guid.Empty; if (task == null) throw new FaultException("Unable to save null task"); TaskrDataContext db = new TaskrDataContext(ConfigurationProvider.GetConnection("Taskr")); if (task.Id == Guid.Empty) { //If a new task is created, instruct SaaSGrid to adjust the limit counter appriopriately. MeterStatus result = SubscriptionContext.Instance.IncrementLimitCounter(Constants.FeatureNumberOfTasks); if (MeterStatus.NotExhausted == result) { try { Task _task = task.MapTo(); db.Tasks.InsertOnSubmit(_task); db.SubmitChanges(); taskId = _task.Id; } catch { SubscriptionContext.Instance.DecrementLimitCounter(Constants.FeatureNumberOfTasks); throw; } } else { throw new LimiterExhaustedException ( Constants.FeatureNumberOfTasks, result, Home.Resources.Task_MaximumLimitReached ); } } else { Task existingTask = db.Tasks.SingleOrDefault(t => t.Id == task.Id); task.MapInto(existingTask); db.SubmitChanges(); taskId = existingTask.Id; } return taskId; }