private void ProcessIncommingUser(string msg) { using (var scope = scopeFactory.CreateScope()) { log.Debug("New User arrived " + msg); UserMessage userMsg = JsonConvert.DeserializeObject <UserMessage>(msg); var repositoryScope = scope.ServiceProvider.GetRequiredService <IRepository <OrganizationCost> >(); var now = DateTime.Now; try { var orgCost = repositoryScope.GetFirst(x => x.Month == now.Month && x.Year == now.Year && x.OrganizationId == userMsg.Message.organizationId); orgCost.UsersAmount = orgCost.UsersAmount + 1; repositoryScope.Update(orgCost); } catch (InvalidOperationException) { OrganizationCost organizationCost = new OrganizationCost() { BugsAmount = 0, Month = now.Month, Year = now.Year, OrganizationId = userMsg.Message.organizationId, UsersAmount = 1 }; repositoryScope.Add(organizationCost); } repositoryScope.Save(); } }
private void ProcessIncommingBug(string msg) { using (var scope = scopeFactory.CreateScope()) { log.Debug("New Bug arrived " + msg); BugMessage bm = JsonConvert.DeserializeObject <BugMessage>(msg); var repositoryScope = scope.ServiceProvider.GetRequiredService <IRepository <OrganizationCost> >(); var now = DateTime.Now; try { var ocost = repositoryScope.GetFirst(x => x.Month == now.Month && x.Year == now.Year && x.OrganizationId == bm.message.organizationId); //ESTA - HAY Q ACTUALIZAR ocost.BugsAmount = ocost.BugsAmount + 1; repositoryScope.Update(ocost); } catch (InvalidOperationException) { //NO ESTA - HAY QUE AGREGAR LA TUPLA OrganizationCost oc = new OrganizationCost() { BugsAmount = 1, Month = now.Month, Year = now.Year, OrganizationId = bm.message.organizationId, UsersAmount = 0 }; repositoryScope.Add(oc); } repositoryScope.Save(); } }