public void TestQueriesAndInsert()
        {
            using (var context = TestDwhDbContext.CreateDWHDbContext()) {
                var referenceRepo = new CRUDRepository <LoadInformation, long>(context);

                var hubRepo       = new HubRepository <H_TestHub_References>(context, HashFunctions.MD5, null);
                var satelliteRepo = new SatelliteRepository <S_TestSatellite_References>(context, HashFunctions.MD5);
                var linkRepo      = new LinkRepository <L_TestLink_References>(context, HashFunctions.MD5, null, DVKeyCaching.Disabled);

                var loadDate = DateTime.Now;

                // REFERENCE ENTRY - inserting and data persistence tests
                var load1Key = referenceRepo.Insert(LoadInfo1);
                var load2Key = referenceRepo.Insert(LoadInfo2);

                var hubList = referenceRepo.Get();
                Assert.NotEmpty(hubList);
                Assert.Equal(2, hubList.Count());
                Assert.False(load1Key == default);
                Assert.False(load2Key == default);

                var loadInfo = referenceRepo.Get(x => x.PrimaryKey == load2Key).Single();

                Assert.Equal(LoadInfo2.RecordSource, loadInfo.RecordSource);
                Assert.Equal(LoadInfo2.LoadedBy, loadInfo.LoadedBy);

                // HUB - referencing
                TestHub1 = hubRepo.Insert(TestHub1, loadDate, loadReference: LoadInfo1);
                TestHub2 = hubRepo.Insert(TestHub2, loadDate, loadReference: LoadInfo2);
                Assert.Equal(load1Key, TestHub1.LoadReference);
                Assert.Equal(load2Key, TestHub2.LoadReference);

                // SATELLITE - referencing
                Hub1Satellite1 = satelliteRepo.Insert(Hub1Satellite1, loadDate, loadReference: LoadInfo1);
                Hub2Satellite1 = satelliteRepo.Insert(Hub2Satellite1, loadDate, loadReference: LoadInfo2);

                Assert.Equal(load1Key, Hub1Satellite1.LoadReference);
                Assert.Equal(load2Key, Hub2Satellite1.LoadReference);

                var satelliteList = satelliteRepo.GetCurrent();
                Assert.NotEmpty(satelliteList);
                Assert.Equal(2, satelliteList.Count());


                // LINK - referencing
                Link1 = linkRepo.Insert(Link1, loadDate, loadReference: LoadInfo1);

                Assert.Equal(load1Key, Link1.LoadReference);

                Link1 = linkRepo.Get().Single();
                Assert.Equal(load1Key, Link1.LoadReference);
            }
        }
Esempio n. 2
0
        public static Conflict GetConflictWithUsers(int id)
        {
            using (var repo = new CRUDRepository <Conflict>())
            {
                return(repo.GetQuery <Conflict>(c => c.Id == id)
                       .Include("UsersInConflicts.User")
                       .Include(c => c.CreatedBy)

                       .Include(c => c.Arbiter)
                       .FirstOrDefault());
            }
        }
Esempio n. 3
0
 public static ConflictState GetConflictState(int conflictId)
 {
     using (var repo = new CRUDRepository <Conflict>())
     {
         var conflict = repo.GetQuery <Conflict>(c => c.Id == conflictId).FirstOrDefault();
         if (conflict == null)
         {
             throw new Exception("Conflict not found");
         }
         return((ConflictState)conflict.State);
     }
 }
Esempio n. 4
0
 public static void DisableUserInConflict(int idConflict, string idUser)
 {
     using (var repo = new CRUDRepository <UsersInConflict>())
     {
         var uic = repo.GetQuery <UsersInConflict>(c => c.IdConflict == idConflict && c.IdUser == idUser).FirstOrDefault();
         if (uic != null)
         {
             uic.Disable = true;
             repo.Update(uic);
         }
     }
 }
Esempio n. 5
0
 public static void MarkUserDeclarationHasCompleted(int idConflict, string idUser)
 {
     using (var repo = new CRUDRepository <UsersInConflict>())
     {
         var uic = repo.GetQuery <UsersInConflict>(c => c.IdConflict == idConflict && c.IdUser == idUser).FirstOrDefault();
         if (uic != null)
         {
             uic.Completed = true;
             repo.Update(uic);
         }
     }
 }
Esempio n. 6
0
 public static void AcceptArbitration(int conflictId, string userId)
 {
     using (var repo = new CRUDRepository <UsersInConflict>())
     {
         var uic = repo.GetQuery <UsersInConflict>(c => c.IdUser == userId && c.IdConflict == conflictId).FirstOrDefault();
         if (uic != null)
         {
             uic.ReadyForArbitration = true;
             repo.Update(uic);
         }
     }
 }
Esempio n. 7
0
 public static List <ResolutionType> ListResolutionTypesForConflict(int conflictTypeId)
 {
     using (var repo = new CRUDRepository <ResolutionType>())
     {
         var resolutionTypes = repo.GetQuery <ResolutionType>(c => c.IdConflictType == conflictTypeId).ToList();
         foreach (var item in resolutionTypes)
         {
             item.ProofFiles = new List <ProofFile>();
         }
         return(resolutionTypes);
     }
 }
Esempio n. 8
0
 public static void AssignArbiterToConflict(int idConflict, string idArbiter)
 {
     using (var repo = new CRUDRepository <Conflict>())
     {
         var conflict = repo.GetQuery <Conflict>(c => c.Id == idConflict).FirstOrDefault();
         if (conflict != null)
         {
             conflict.State             = (int)ConflictState.ArbiterAssigned;
             conflict.IdArbiterAssigned = idArbiter;
             repo.Update(conflict);
         }
     }
 }
Esempio n. 9
0
 public static Debate CloseDebate(int id)
 {
     using (var repo = new CRUDRepository <Debate>())
     {
         var debate = repo.GetQuery <Debate>(c => c.Id == id).FirstOrDefault();
         if (debate != null)
         {
             debate.Closed = true;
             repo.Update(debate);
         }
         return(debate);
     }
 }
Esempio n. 10
0
        public static Conflict GetConflictForResolutionContestation(int idConflict)
        {
            using (var repo = new CRUDRepository <Conflict>())
            {
                var conflict = repo.GetQuery <Conflict>(c => c.Id == idConflict)
                               .Include("UsersInConflicts.User")
                               .Include(c => c.Invitations)
                               .Include("Events.Disagreements")
                               .FirstOrDefault();

                return(conflict);
            }
        }
Esempio n. 11
0
 public static Conflict UpdateConflictState(int id, int state)
 {
     using (var repo = new CRUDRepository <Conflict>())
     {
         var conflict = repo.GetQuery <Conflict>(c => c.Id == id).FirstOrDefault();
         if (conflict != null)
         {
             conflict.State = state;
             repo.Update(conflict);
         }
         return(conflict);
     }
 }
Esempio n. 12
0
 public static List <string> GetUsersForDebate(int debateId)
 {
     using (var repo = new CRUDRepository <Debate>())
     {
         var res = repo.GetQuery <Debate>(c => c.Id == debateId)
                   .Include("Event.Conflict")
                   .Select(c => c.Event.Conflict)
                   .FirstOrDefault();
         var user = repo.GetQuery <AspNetUser>()
                    .Where(c => c.UsersInConflicts.Any(d => d.IdConflict == res.Id))
                    .ToList();
         return(user.Select(c => c.Email).ToList());
     }
 }
Esempio n. 13
0
        public static Email AddEmail(string to, string subject, string body, Guid guid)
        {
            using (var repo = new CRUDRepository <Email>())
            {
                Email email = new Email();
                email.Id      = guid;
                email.to      = to;
                email.subject = subject;
                email.body    = body;

                email = repo.Add(email);
                return(email);
            }
        }
Esempio n. 14
0
 public static Invitation AddInvitation(Invitation invitation)
 {
     using (var repo = new CRUDRepository <Invitation>())
     {
         if (!repo.GetQuery <Invitation>().Any(c => c.IdConflict == invitation.IdConflict && c.Email == invitation.Email))
         {
             return(repo.Add(invitation));
         }
         else
         {
             return(null);
         }
     }
 }
Esempio n. 15
0
 public static MeetingDebate UpdateMeetingDebate(MeetingDebate debate)
 {
     using (var repo = new CRUDRepository <MeetingDebate>())
     {
         var prev = repo.GetQuery <MeetingDebate>(c => c.Id == debate.Id).FirstOrDefault();
         if (prev != null)
         {
             prev.Date             = debate.Date;
             prev.EstimateDuration = debate.EstimateDuration;
         }
         repo.Update(prev);
         return(prev);
     }
 }
Esempio n. 16
0
 public static bool AutoConfirmUser(string idUser)
 {
     using (var repo = new CRUDRepository <AspNetUser>())
     {
         var user = repo.GetQuery <AspNetUser>(c => c.Id == idUser).FirstOrDefault();
         if (user != null)
         {
             user.EmailConfirmed = true;
             repo.Update(user);
             return(true);
         }
         return(false);
     }
 }
Esempio n. 17
0
 public static void UpdateUserMainCompany(int idCompany, string iduser)
 {
     using (var repo = new CRUDRepository <UserCompany>())
     {
         var userCompany = repo.GetQuery <UserCompany>(u => u.IdUser == iduser && u.IdCompany == idCompany).FirstOrDefault();
         if (userCompany == null)
         {
             UserCompany uc = new UserCompany();
             uc.IdCompany = idCompany;
             uc.IdUser    = iduser;
             repo.Add(uc);
         }
     }
 }
Esempio n. 18
0
        public static void RemoveEvent(int id)
        {
            using (var repo = new CRUDRepository <Event>())
            {
                var elt = repo.GetQuery <Event>(c => c.Id == id).Include(c => c.ProofFiles).FirstOrDefault();

                if (elt != null)
                {
                    elt.ProofFiles = null;
                    repo.Update(elt);
                    repo.Delete(elt);
                }
            }
        }
Esempio n. 19
0
 public static ProofFile AddFile(ProofFile file, int eventId)
 {
     using (var repo = new CRUDRepository <Event>())
     {
         var evt = repo.GetQuery <Event>(c => c.Id == eventId).FirstOrDefault();
         if (evt != null)
         {
             file.UploadDate = DateTime.Now;
             evt.ProofFiles.Add(file);
         }
         repo.Update(evt);
         return(file);
     }
 }
Esempio n. 20
0
 public static Conflict UpdateConflictType(int idConflict, int conflictTypeId)
 {
     using (var repo = new CRUDRepository <Conflict>())
     {
         var cft = repo.GetQuery <Conflict>(c => c.Id == idConflict)
                   .FirstOrDefault();
         if (cft != null)
         {
             cft.IdConflictType = conflictTypeId;
             repo.Update(cft);
         }
         return(cft);
     }
 }
Esempio n. 21
0
        public static List <ConflictType> ListConflictsType(int?category = null)
        {
            using (var repo = new CRUDRepository <ConflictType>())
            {
                var elts = repo.GetQuery <ConflictType>().Where(c => c.IsMapped);

                if (category != null)
                {
                    elts = elts.Where(c => c.Code.StartsWith(category.Value.ToString()));
                }

                return(elts.ToList());
            }
        }
Esempio n. 22
0
 public static bool IsArbiterForConflict(int conflictId, string idUser)
 {
     using (var repo = new CRUDRepository <Conflict>())
     {
         var conflict = repo.GetQuery <Conflict>(c => c.Id == conflictId).FirstOrDefault();
         if (conflict != null)
         {
             return(conflict.IdArbiterAssigned == idUser);
         }
         else
         {
             return(false);
         }
     }
 }
Esempio n. 23
0
 public static ConflictStateHistoric UpdateConflictStateHistoric(ConflictStateHistoric csh)
 {
     using (var repo = new CRUDRepository <ConflictStateHistoric>())
     {
         var conflictStateHistoric = repo.GetQuery <ConflictStateHistoric>(c => c.Id == csh.Id).FirstOrDefault();
         if (conflictStateHistoric != null)
         {
             conflictStateHistoric.ConflictStateId   = csh.ConflictStateId;
             conflictStateHistoric.ConflictStateName = csh.ConflictStateName;
             conflictStateHistoric.CountDown         = csh.CountDown;
             repo.Update(conflictStateHistoric);
         }
         return(conflictStateHistoric);
     }
 }
Esempio n. 24
0
 public static void AcceptConflict(int idConflict, string idArbiter, bool noconflict, bool legitimate)
 {
     using (var repo = new CRUDRepository <Conflict>())
     {
         var conflict = repo.GetQuery <Conflict>(c => c.Id == idConflict && c.IdArbiterAssigned == idArbiter).FirstOrDefault();
         if (conflict != null)
         {
             conflict.HasArbiterAccepted                   = true;
             conflict.ArbiterRecognizeLegitimate           = legitimate;
             conflict.ArbiterRecognizeNoConflictOfInterest = noconflict;
             conflict.State = (int)ConflictState.ArbitrationStarted;
             repo.Update(conflict);
         }
     }
 }
Esempio n. 25
0
 public static Debate ReOpenDebate(int id, int countDown)
 {
     using (var repo = new CRUDRepository <Debate>())
     {
         var debate = repo.GetQuery <Debate>(c => c.Id == id).FirstOrDefault();
         if (debate != null)
         {
             debate.Closed     = false;
             debate.CreateDate = DateTime.Now;
             debate.CountDown  = countDown;
             repo.Update(debate);
         }
         return(debate);
     }
 }
Esempio n. 26
0
 public static int GetDefaultEventConflictType(int idEvent)
 {
     using (var repo = new CRUDRepository <DefaultEvent>())
     {
         var defaultEvent = repo.GetQuery <DefaultEvent>(c => c.Id == idEvent).FirstOrDefault();
         if (defaultEvent != null)
         {
             return(defaultEvent.IdConflictType);
         }
         else
         {
             return(0);
         }
     }
 }
Esempio n. 27
0
 public static void UpdatePresentation(ArbiterInformation arbiterInformation)
 {
     using (var repo = new CRUDRepository <ArbiterInformation>())
     {
         if (arbiterInformation != null)
         {
             var previous = repo.GetQuery <ArbiterInformation>(c => c.Id == arbiterInformation.Id).FirstOrDefault();
             if (previous != null)
             {
                 previous.Presentation = arbiterInformation.Presentation;
                 repo.Update(previous);
             }
         }
     }
 }
Esempio n. 28
0
 public static void RemoveRolesToUser(string userId, string[] rolesId)
 {
     using (var repo = new CRUDRepository <AspNetUser>())
     {
         var user = repo.GetQuery <AspNetUser>(c => c.Id == userId).Include(c => c.Roles).FirstOrDefault();
         foreach (var item in rolesId)
         {
             var role = repo.GetQuery <AspNetRole>(c => c.Id == item).FirstOrDefault();
             if (role != null && user.Roles.Any(c => c.Id == role.Id))
             {
                 user.Roles.Remove(role);
             }
         }
         repo.Update(user);
     }
 }
Esempio n. 29
0
        public static LegalDocument Update(LegalDocument document)
        {
            using (var repo = new CRUDRepository <LegalDocument>())
            {
                var doc = repo.GetQuery <LegalDocument>(x => x.Id == document.Id).FirstOrDefault();
                if (doc != null)
                {
                    doc.Filename = document.Filename;
                    doc.Url      = document.Url;

                    repo.Update(doc);
                    return(doc);
                }
                return(null);
            }
        }
Esempio n. 30
0
 public static Conflict UpdateConflict(Conflict conflict)
 {
     using (var repo = new CRUDRepository <Conflict>())
     {
         var cft = repo.GetQuery <Conflict>(c => c.Id == conflict.Id)
                   .FirstOrDefault();
         if (cft != null)
         {
             cft.State               = conflict.State;
             cft.HasArbitralClause   = conflict.HasArbitralClause;
             cft.AskedForArbitration = conflict.AskedForArbitration;
             repo.Update(cft);
         }
         return(cft);
     }
 }
Esempio n. 31
0
        public ActionResult Index(string sortOrder,string alertMsg, string alertType)
        {
            ViewBag.AlertMsg = alertMsg;
            ViewBag.AlertType = alertType;

            CRUDRepository<Books> _repository = new CRUDRepository<Books>();

            var model = _repository.GetAll();

            ViewBag.TitleSortParm = sortOrder == "Título" ? "TítuloDesc" : "Título";
            ViewBag.AutorSortParm = sortOrder == "Autor" ? "AutorDesc" : "Autor";
            ViewBag.YearSortParm = sortOrder == "Ano" ? "AnoDesc" : "Ano";
            ViewBag.IdSortParm = sortOrder == "#" ? "#Desc" : "#";

            var books = from b in model select b;
            switch (sortOrder)
            {
                case "TítuloDesc":
                    books = books.OrderByDescending(b => b.Title);
                    break;
                case "Título":
                    books = books.OrderBy(b => b.Title);
                    break;
                case "AutorDesc":
                    books = books.OrderByDescending(b => b.Autor);
                    break;
                case "Autor":
                    books = books.OrderBy(b => b.Autor);
                    break;
                case "AnoDesc":
                    books = books.OrderByDescending(b => b.Year);
                    break;
                case "Ano":
                    books = books.OrderBy(b => b.Year);
                    break;
                case "#Desc":
                    books = books.OrderByDescending(b => b.Id);
                    break;
                case "#":
                    books = books.OrderBy(b => b.Id);
                    break;
                default:
                    books = books.OrderBy(b => b.Id);
                    break;
            }
            return View("List", books);
        }