コード例 #1
0
ファイル: RepoTests.cs プロジェクト: tara-sova/REAL.NET
        public void RepoShallAllowToCreateAMetamodelProgrammatically()
        {
            var repo  = RepoFactory.Create();
            var model = repo.CreateModel("TestModel", "InfrastructureMetamodel");

            var node1 = model.CreateElement("Node");

            node1.Name = "TestNode1";
            node1.AddAttribute("testAttribute", AttributeKind.Int, "10");

            var node2 = model.CreateElement("Node");

            node2.Name = "TestNode2";
            node2.AddAttribute("otherAttribute", AttributeKind.String, "Ololo");

            var generalization = model.CreateElement("Generalization") as IEdge;

            generalization.From = node2;
            generalization.To   = node1;

            Assert.AreEqual("testAttribute", node1.Attributes.First().Name);
            Assert.AreEqual("10", node1.Attributes.First().StringValue);

            Assert.AreEqual("otherAttribute", node2.Attributes.First().Name);
            Assert.AreEqual("Ololo", node2.Attributes.First().StringValue);
        }
コード例 #2
0
        public IHttpActionResult GetAll()
        {
            IRepository        repo = RepoFactory.Create();
            List <DVDListView> DVDs = repo.GetAll().ToList();

            return(Ok(DVDs));
        }
コード例 #3
0
        public virtual ActionResult DeleteBinaryFile(int id, int?parentId, string pn, HttpDelete ignore)
        {
            using (new EFUnitOfWork <DbContextT>())
            {
                var entityItem   = RepoFactory.Create <EntityT>().GetById(id);
                var mvcModelItem = (ChildMvcModelT) new ChildMvcModelT().MapFromObject(entityItem);
                if (parentId == null)
                {
                    var parent = mvcModelItem.GetParentEntity(entityItem);
                    if (parent != null)
                    {
                        parentId = parent.Id;
                    }
                }

                //see if pn is a required property
                if (Attribute.GetCustomAttribute(typeof(ChildMvcModelT).GetProperty(pn), typeof(RequiredAttribute), true) != null)
                {
                    TempData.Supermodel().NextPageModalMessage = "Cannot delete required field";
                    var routeValues = new RouteValueDictionary(ControllerContext.RouteData.Values);
                    routeValues["Action"] = "Edit";
                    routeValues.Add("parentId", parentId);
                    return(RedirectToRoute(routeValues));
                }

                var file = (BinaryFileMvcModel)mvcModelItem.PropertyGet(pn);

                file.Empty();
                entityItem = (EntityT)mvcModelItem.MapToObject(entityItem);
                return(AfterBinaryDelete(id, parentId, entityItem, mvcModelItem));
            }
        }
コード例 #4
0
        public virtual ActionResult Edit(int id, int?parentId, HttpPut ignore)
        {
            using (new EFUnitOfWork <DbContextT>())
            {
                if (id == 0)
                {
                    throw new SupermodelException("CRUDControllerBase.Edit[Post]: id == 0");
                }

                var            entityItem = RepoFactory.Create <EntityT>().GetById(id);
                ChildMvcModelT mvcModelItem;
                try
                {
                    entityItem = TryUpdateEntity(entityItem, null, out mvcModelItem);
                    if (parentId == null)
                    {
                        var parent = mvcModelItem.GetParentEntity(entityItem);
                        if (parent != null)
                        {
                            parentId = parent.Id;
                        }
                    }
                }
                catch (ModelStateInvalidException ex)
                {
                    DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction
                    return(View(ex.Model));
                }
                return(AfterUpdate(id, parentId, entityItem, mvcModelItem));
            }
        }
コード例 #5
0
        public virtual ActionResult Edit(int id, int?parentId, HttpDelete ignore)
        {
            EntityT entityItem = null;

            using (new EFUnitOfWork <DbContextT>())
            {
                try
                {
                    entityItem = RepoFactory.Create <EntityT>().GetById(id);
                    if (parentId == null)
                    {
                        var mvcModelItem = (ChildMvcModelT) new ChildMvcModelT().MapFromObject(entityItem);
                        var parent       = mvcModelItem.GetParentEntity(entityItem);
                        if (parent != null)
                        {
                            parentId = parent.Id;
                        }
                    }
                    entityItem.Delete();
                }
                catch (UnableToDeleteException ex)
                {
                    DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction
                    TempData.Supermodel().NextPageModalMessage = ex.Message;
                }
                catch (Exception)
                {
                    DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction
                    TempData.Supermodel().NextPageModalMessage = "PROBLEM!!!\\n\\nUnable to delete. Most likely reason: references from other entities.";
                }
            }
            return(AfterDelete(id, parentId, entityItem));
        }
コード例 #6
0
        public DutyDeviationShardActor()
            : base(2, 10, NewDutyDtoDecorator)
        {
            this.repoDeviation = RepoFactory.Create <DeviationShard>(2, 10, NewDeviationDtoDecorator);

            this.Receive <ApiRequestContext <LoadDutyplanRequest, long[]> >(this.HandleLoadDutyplanRequest);
        }
コード例 #7
0
        public override object MapToObjectCustom(object obj, Type objType)
        {
            var result = (EntityT)base.MapToObjectCustom(obj, objType);

            if (result == null)
            {
                return(null);
            }

            var parentEntity = GetParentEntity((EntityT)obj);

            if (parentEntity == null && ParentId != null ||
                parentEntity != null && parentEntity.Id != ParentId)
            {
                if (ParentId == null)
                {
                    SetParentEntity((EntityT)obj, null);
                }
                else
                {
                    SetParentEntity((EntityT)obj, RepoFactory.Create <ParentEntityT>().GetById((int)ParentId));
                }
            }
            return(result);
        }
コード例 #8
0
        public void CanDeleteDVD()
        {
            IRepository repo = RepoFactory.Create();

            repo.DeleteDvD(1);
            List <DVDListView> DVDs = repo.GetAll().ToList();

            Assert.AreEqual(1, DVDs.Count());
        }
コード例 #9
0
 public void DoIt()
 {
     var repository = RepoFactory.Create <ToDo>();
     var results    = repository.Query()
                      .Select(e => e.Id, e => e.Task, e => e.CreatedDate)
                      .Where(e => e.IsCompleted == false)
                      .Go();
     // ...
 }
コード例 #10
0
ファイル: CRUDController.cs プロジェクト: ibasin/Supermodel
 public virtual ActionResult List()
 {
     using (new EFUnitOfWork <DbContextT>(ReadOnly.Yes))
     {
         var entities  = RepoFactory.Create <EntityT>().GetAll();
         var mvcModels = new List <MvcModelT>();
         mvcModels = (List <MvcModelT>)mvcModels.MapFromObject(entities);
         mvcModels = mvcModels.OrderBy(p => p.Label).ToList();
         return(View(mvcModels));
     }
 }
コード例 #11
0
        public IHttpActionResult GetByID(int id)
        {
            IRepository   repo     = RepoFactory.Create();
            DVDDetailView selected = repo.GetByID(id);

            if (selected == null)
            {
                return(NotFound());
            }
            return(Ok(selected));
        }
コード例 #12
0
 public IHttpActionResult AddDVD(DVD ToAdd)
 {
     if (!string.IsNullOrWhiteSpace(ToAdd.Title) && !string.IsNullOrWhiteSpace(ToAdd.Director) && ToAdd.realeaseYear > 0)
     {
         IRepository repo = RepoFactory.Create();
         repo.AddDVD(ToAdd);
         return(Created($"DVD/{ToAdd.DVDID}", ToAdd));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
コード例 #13
0
        public IHttpActionResult UpdateDVD(int id, DVD ToEdit)
        {
            if (ModelState.IsValid)
            {
                IRepository repo = RepoFactory.Create();
                repo.EditDVD(ToEdit);

                return(Ok(repo.GetByID(id)));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
コード例 #14
0
        public void CanAddDVD()
        {
            IRepository repo  = RepoFactory.Create();
            DVD         ToADD = new DVD {
                Title = "TestMovie", Director = "Test", RatingID = 1, Note = "nononon", realeaseYear = 1977
            };

            repo.AddDVD(ToADD);
            List <DVDListView> DVDs = repo.GetAll().ToList();

            Assert.AreEqual(3, DVDs.Count());
            Assert.AreEqual(3, DVDs[2].DVDID);
            Assert.AreEqual(DVDs[2].Title, "TestMovie");
        }
コード例 #15
0
ファイル: CRUDController.cs プロジェクト: ibasin/Supermodel
        public virtual ActionResult Edit(int id, HttpGet ignore)
        {
            using (new EFUnitOfWork <DbContextT>(ReadOnly.Yes))
            {
                if (id == 0)
                {
                    return(View(new MvcModelT().MapFromObject(new EntityT().ConstructVirtualProperties())));
                }

                var entityItem   = RepoFactory.Create <EntityT>().GetById(id);
                var mvcModelItem = (MvcModelT) new MvcModelT().MapFromObject(entityItem);

                return(View(mvcModelItem));
            }
        }
コード例 #16
0
        public void DoIt()
        {
            var repository = RepoFactory.Create <ToDo>();
            var results    = repository.Query()
                             .Select(e => e.Id, e => e.Task, e => e.CreatedDate)
                             .Where(e => e.IsCompleted == false)
                             .Go();

            Console.WriteLine("Id,Task,Completed,Created");
            foreach (var row in results)
            {
                Console.WriteLine($"{row.Id},{row.Task},{row.IsCompleted},{row.CreatedDate}");
            }

            Console.ReadLine();
        }
コード例 #17
0
        public virtual ActionResult Edit(int id, int?parentId, HttpGet ignore)
        {
            using (new EFUnitOfWork <DbContextT>(ReadOnly.Yes))
            {
                ChildMvcModelT mvcModelItem;
                if (id == 0)
                {
                    mvcModelItem = new ChildMvcModelT {
                        ParentId = parentId
                    };                                                         //We set parentID twice, in case we may need it during MapFromObject
                    mvcModelItem          = (ChildMvcModelT)mvcModelItem.MapFromObject(new EntityT().ConstructVirtualProperties());
                    mvcModelItem.ParentId = parentId;
                    return(View(mvcModelItem));
                }

                var entityItem = RepoFactory.Create <EntityT>().GetById(id);
                mvcModelItem = (ChildMvcModelT) new ChildMvcModelT().MapFromObject(entityItem);
                return(View(mvcModelItem));
            }
        }
コード例 #18
0
        public IHttpActionResult FindByQuery(string category, string searchTerm)
        {
            IRepository          repo    = RepoFactory.Create();
            List <DVDDetailView> results = new List <DVDDetailView>();

            switch (category.ToLower())
            {
            case "title":
                results = repo.FindByTitle(searchTerm).ToList();
                break;

            case "director":
                results = repo.FindByDirector(searchTerm).ToList();
                break;

            case "realeaseyear":
                results = repo.FindbyYear(int.Parse(searchTerm)).ToList();
                break;
            }
            return(Ok(results));
        }
コード例 #19
0
        public void DoIt()
        {
            var repository = RepoFactory.Create <ToDo>();
            var results    = repository.Query()
                             .Select(e => e.Id, e => e.Task, e => e.CreatedDate)
                             .OrderBy(e => e.Id)
                             .Page(10, 3)
                             .Go();

            foreach (var item in results)
            {
                Console.WriteLine($"{item.Id},{item.Task},{item.CreatedDate} ");
            }
            var repository2 = RepoFactory.Create <TwoRemark>();
            var results2    = repository2.Query()
                              .Select(t => t.Task, t => t.Remark)
                              .Go();


            foreach (var item in results2)
            {
                Console.WriteLine($"{item.Task},{item.Remark} ");
            }

            var repository3 = RepoFactory.Create <ToDo>();

            var result3 = repository3.Query().From("a")
                          .InnerJoin <TwoRemark>("b").On <TwoRemark>((l, r) => l.Task == r.Task, "a", "b").OrderBy(e => e.Id, "a").Page(10, 3).Go();

            //Console.WriteLine(result3);


            // var result4 = result3.Go();
            foreach (var item in result3)
            {
                Console.WriteLine($"{item.Id},{item.Task},{item.CreatedDate} ");
            }
        }
コード例 #20
0
ファイル: CRUDController.cs プロジェクト: ibasin/Supermodel
        public virtual ActionResult Edit(int id, HttpDelete ignore)
        {
            EntityT entityItem = null;

            using (new EFUnitOfWork <DbContextT>())
            {
                try
                {
                    entityItem = RepoFactory.Create <EntityT>().GetById(id);
                    entityItem.Delete();
                }
                catch (UnableToDeleteException ex)
                {
                    DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction
                    TempData.Supermodel().NextPageModalMessage = ex.Message;
                }
                catch (Exception)
                {
                    DbContextAmbientContext <DbContextT> .CurrentDbContext.CommitOnDispose = false; //rollback the transaction
                    TempData.Supermodel().NextPageModalMessage = "PROBLEM!!!\\n\\nUnable to delete. Most likely reason: references from other entities.";
                }
            }
            return(AfterDelete(id, entityItem));
        }
コード例 #21
0
 protected AbstractShardActor(uint minResponse, uint maxResponse, Action <IRepo <T>, T, dynamic> repoDecorator)
 {
     this.Rng  = new Random();
     this.Repo = RepoFactory.Create(minResponse, maxResponse, repoDecorator);
 }
コード例 #22
0
 protected AtkHandle()
 {
     azNormalSet = AzNormalSet.GetAzNormalSet();
     repository  = RepoFactory.Create <TEntity>();
 }
コード例 #23
0
        public void DeleteDvd(int id)
        {
            IRepository repo = RepoFactory.Create();

            repo.DeleteDvD(id);
        }
コード例 #24
0
 public static void Create()
 {
     repo = RepoFactory.Create();
 }
コード例 #25
0
ファイル: CRUDController.cs プロジェクト: ibasin/Supermodel
 public virtual ActionResult GetBinaryFile(int id, string pn, HttpGet ignore)
 {
     using (new EFUnitOfWork <DbContextT>(ReadOnly.Yes))
     {
         var          mvcModelItem = (MvcModelT) new MvcModelT().MapFromObject(RepoFactory.Create <EntityT>().GetById(id));
         var          file         = (BinaryFileMvcModel)mvcModelItem.PropertyGet(pn);
         const string mimeType     = "application/octet-stream";
         //var mimeType = Common.GetContentTypeHeader(file.Name);
         if (file == null || file.IsEmpty)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
         }
         return(File(file.BinaryContent, mimeType, file.Name));
     }
 }