public HttpResponseMessage Post([FromBody] ActivityConcept activityConcept) { var item = Uow.ActivityConcepts.GetByIdWithRules(activityConcept.Id); var response = HttpStatusCode.Accepted; //update if (null != item) { item.Name = activityConcept.Name; item.Description = activityConcept.Description; item.Rules.Clear(); foreach (var rule in activityConcept.Rules) { item.Rules.Add(rule.Id != 0 ? Uow.FilterRules.GetById(rule.Id) : rule); } Uow.ActivityConcepts.Update(item); } else //create { var rules = activityConcept.Rules.ToList(); activityConcept.Rules.Clear(); foreach (var rule in rules) { activityConcept.Rules.Add(rule.Id != 0 ? Uow.FilterRules.GetById(rule.Id) : rule); } Uow.ActivityConcepts.Add(activityConcept); response = HttpStatusCode.Created; } Uow.Commit(); return(new HttpResponseMessage(response)); }
public void Update(ActivityConcept entity) { var entry = GetById(entity.Id); if (entry != null) { _list.Remove(entry); _list.Add(entity); } }
public void TestUpdate() { var entry = new ActivityConcept() { Description = "Desc1", Id = 1, Name = "Name1Updated", Rules = new List <FilterRule>() }; var target = GetTarget(); var response = target.Post(entry); var updated = _mockUow.ActivityConcepts.GetById(entry.Id); Assert.AreEqual(response.StatusCode, HttpStatusCode.Accepted); Assert.AreEqual(updated.Name, "Name1Updated"); }
public void TestCreate() { var entry = new ActivityConcept() { Description = "Desc99", Id = 99, Name = "Name99", Rules = new List <FilterRule>() }; var target = GetTarget(); var count = _mockUow.ActivityConcepts.GetAll().Count(); var response = target.Post(entry); Assert.AreEqual(response.StatusCode, HttpStatusCode.Created); Assert.AreEqual(count + 1, _mockUow.ActivityConcepts.GetAll().Count()); }
private void GetMeasuresFromActivityConcept(ActivityConcept concept) { var measure = new Measure() { Name = concept.Name, Time = 0 }; foreach (var filterRule in concept.Rules) { try { var activities = _attUow.Activities.GetAll(); var list = _activityQueryExecuter.Query(activities, filterRule.Expression).ToList(); /*var sql = "SELECT * FROM Activities"; * * if (!String.IsNullOrEmpty(filterRule.Expression)) * { * sql += " WHERE " + filterRule.Expression; * } * * var list = _attUow.Activities.GetBySQL(sql).ToList();*/ var time = list.Sum(m => m.Life); measure.Time += time; var monthList = list.Where(m => m.Date.Year == DateTime.Now.Year && m.Date.Month == DateTime.Now.Month).ToList(); var timeThisMonth = monthList.Sum(m => m.Life); measure.TimeMonthAccumulation += timeThisMonth; var todayList = monthList.Where(m => m.Date.Day == DateTime.Now.Day).ToList(); var timeToday = todayList.Sum(m => m.Life); measure.TimeToday += timeToday; } catch (Exception e) { Measures.Add(new Measure() { Name = e.Message, Time = 0.0 }); } } measure.TimeMonthAccumulation -= measure.TimeToday; measure.TimeRestAccumulation = Math.Round((measure.Time - measure.TimeMonthAccumulation - measure.TimeToday), 2); Measures.Add(measure); }
public void Delete(ActivityConcept entity) { _list.Remove(entity); }
public void Add(ActivityConcept entity) { _list.Add(entity); }