Ejemplo n.º 1
0
 public PlanetController()
 {
     // This is temporary code, just for testing
     if (InfoRepository.SWSpecies.Count == 0) // only do this if it hasn't been done already
     {
         species = new Species()
         {
             SpeciesName    = "Wookiee",
             Classification = "mammal",
             Designation    = "sentient",
             AvgHeight      = 210,
             Language       = "Shyriiwook",
             AvgLifeSpan    = 400,
             Homeworld      = new Planet()
             {
                 PlanetName       = "Kashyyyk",
                 RotationalPeriod = 26,
                 OrbitalPeriod    = 381,
                 Diameter         = 12765,
                 Climate          = "tropical",
                 Gravity          = 1
             }
         };
         InfoRepository.AddSpecies(species);
     }
 }
Ejemplo n.º 2
0
        private void LoadInfoData()
        {
            TracktorDb        context  = new TracktorDb();
            InfoRepository    infoRepo = new InfoRepository(context);
            List <InfoEntity> infos    = infoRepo.GetAll().ToList();

            AllInfos = new BindingList <InfoEntity>(infos);
        }
        // GET: Database
        public ActionResult Index()
        {
            ViewBag.Title = "Database Page";

            var repo = new InfoRepository();

            return(View(new DatabaseUpdateModel(repo.GetInfo())));
        }
Ejemplo n.º 4
0
        public void Info_Count_When_All_Populated_Should_Be_Fifteen()
        {
            fixture.PopulateAll();
            var repository = new InfoRepository(fixture.context);
            var c          = repository.Get().Count();

            Assert.Equal(15, c);
        }
Ejemplo n.º 5
0
        public void Info_Count_When_Partial_Populated_Should_Be_Two()
        {
            fixture.PopulatePartial();
            var repository   = new InfoRepository(fixture.context);
            var contactCount = repository.Get().Count();

            Assert.Equal(2, contactCount);
        }
Ejemplo n.º 6
0
        public InfoController
            (InfoRepository InfoRepository
            , FileConfig fileConfig)

        {
            _InfoRepository = InfoRepository;
            _fileConfig     = fileConfig;
        }
Ejemplo n.º 7
0
 public frmPrimary()
 {
     InitializeComponent();
     dbPath    = string.Empty;
     folderImg = string.Empty;
     db        = Init();
     rpLink    = new LinkRepository(db);
     rpMovie   = new MovieRepository(db);
     rpInfo    = new InfoRepository(db);
 }
Ejemplo n.º 8
0
        public void Controller_Get_Should_Be_NoContentResult()
        {
            var fixture    = new DbContextFixture();
            var logger     = new Mock <ILogger <InfosController> >().Object;
            var repository = new InfoRepository(fixture.context);
            var controller = new InfosController(logger, repository);
            ActionResult <IQueryable <Info> > result = controller.Get();

            result.Result.Should().BeOfType <NoContentResult>();
        }
Ejemplo n.º 9
0
        public void Add_A_Info_When_Partial_Populated_Should_Be_Three()
        {
            fixture.PopulatePartial();
            var repository = new InfoRepository(fixture.context);

            repository.Add(InfoEntityTypeConfiguration.InfoSeed.ElementAt(3));
            var count = repository.Get().Count();

            Assert.Equal(3, count);
        }
Ejemplo n.º 10
0
        public void Controller_Get_ById_Should_Be_NoContentResult()
        {
            var fixture                = new DbContextFixture();
            var logger                 = new Mock <ILogger <InfosController> >().Object;
            var repository             = new InfoRepository(fixture.context);
            var controller             = new InfosController(logger, repository);
            var e                      = InfoEntityTypeConfiguration.InfoSeed.First();
            ActionResult <Info> result = controller.Get(e.ContactId, e.InfoTypeId);

            result.Result.Should().BeOfType <NoContentResult>();
        }
Ejemplo n.º 11
0
        public void Controller_Delete_Should_Be_NotFound()
        {
            var fixture                = new DbContextFixture();
            var logger                 = new Mock <ILogger <InfosController> >().Object;
            var repository             = new InfoRepository(fixture.context);
            var controller             = new InfosController(logger, repository);
            var entity                 = InfoEntityTypeConfiguration.InfoSeed.ElementAt(1);
            ActionResult <Info> result = controller.Delete(entity.ContactId, entity.InfoTypeId);

            result.Result.Should().BeOfType <NotFoundResult>();
        }
Ejemplo n.º 12
0
        public void Controller_Post_Should_Be_BadRequest()
        {
            var fixture = new DbContextFixture();
            var logger  = new Mock <ILogger <InfosController> >().Object;

            fixture.PopulateAll();
            var repository             = new InfoRepository(fixture.context);
            var controller             = new InfosController(logger, repository);
            ActionResult <Info> result = controller.Post(InfoEntityTypeConfiguration.InfoSeed.ElementAt(1));

            result.Result.Should().BeOfType <BadRequestResult>();
        }
        public ActionResult UpdateOrdersDone()
        {
            var repo = new InfoRepository();

            var info = repo.GetInfo();

            info.OrdersLastUpdated = DateTime.Now;

            repo.Update(info);

            return(Content(""));
        }
Ejemplo n.º 14
0
        public void Controller_Delete_Should_Be_OkResult()
        {
            var fixture = new DbContextFixture();
            var logger  = new Mock <ILogger <InfosController> >().Object;

            fixture.PopulatePartial();
            var repository             = new InfoRepository(fixture.context);
            var controller             = new InfosController(logger, repository);
            var entity                 = InfoEntityTypeConfiguration.InfoSeed.ElementAt(1);
            var e                      = repository.Find(entity.ContactId as object, entity.InfoTypeId as object).Result;
            ActionResult <Info> result = controller.Delete(e.ContactId, e.InfoTypeId);

            result.Result.Should().BeOfType <OkObjectResult>();
        }
Ejemplo n.º 15
0
        public void Controller_Patch_Should_Be_BadRequest()
        {
            var fixture    = new DbContextFixture();
            var logger     = new Mock <ILogger <InfosController> >().Object;
            var repository = new InfoRepository(fixture.context);
            var controller = new InfosController(logger, repository);
            var e          = InfoEntityTypeConfiguration.InfoSeed.ElementAt(2);
            var delta      = new Delta <Info>(typeof(Info));

            delta.TrySetPropertyValue(nameof(Info.Data), e.Data);
            ActionResult <Info> result = controller.Patch(e.ContactId, e.InfoTypeId, delta);

            result.Result.Should().BeOfType <BadRequestResult>();
        }
Ejemplo n.º 16
0
        public void Remove_A_Info_When_All_Populated_Should_Be_FourTeen()
        {
            fixture.PopulateAll();
            var repository = new InfoRepository(fixture.context);
            var id         = InfoEntityTypeConfiguration.InfoSeed.ElementAt(2).ContactId;
            var InfoTypeId = InfoEntityTypeConfiguration.InfoSeed.ElementAt(2).InfoTypeId;
            var entity     = repository.Find(id as object, InfoTypeId as object).Result;

            repository.Remove(entity);
            var entities = repository.Get();
            var count    = entities.Count();

            Assert.Equal(14, count);
        }
Ejemplo n.º 17
0
        public void Update_the_Data_Of_Info_Should_Not_Be_Same()
        {
            fixture.PopulateAll();
            var repository = new InfoRepository(fixture.context);
            var contactId  = InfoEntityTypeConfiguration.InfoSeed.ElementAt(2).ContactId;
            var infoTypeId = InfoEntityTypeConfiguration.InfoSeed.ElementAt(2).InfoTypeId;
            var data       = InfoEntityTypeConfiguration.InfoSeed.ElementAt(2).Data;
            var entity     = repository.Find(contactId as object, infoTypeId as object).Result;

            entity.Data = "F";
            repository.Update(entity);
            var entityUpdated = repository.Find(contactId as object, infoTypeId as object).Result;

            Assert.NotEqual(data, entityUpdated.Data);
        }
Ejemplo n.º 18
0
        public void Controller_Patch_Should_Be_OkResult()
        {
            var fixture = new DbContextFixture();
            var logger  = new Mock <ILogger <InfosController> >().Object;

            fixture.PopulateAll();
            var repository = new InfoRepository(fixture.context);
            var controller = new InfosController(logger, repository);
            var entity     = InfoEntityTypeConfiguration.InfoSeed.ElementAt(1);
            var e          = repository.Find(entity.ContactId as object, entity.InfoTypeId as object).Result;

            e.Data = "Gg";
            var delta = new Delta <Info>(typeof(Info));

            delta.TrySetPropertyValue(nameof(Info.Data), e.Data);
            ActionResult <Info> result = controller.Patch(e.ContactId, e.InfoTypeId, delta);

            result.Result.Should().BeOfType <OkObjectResult>();
        }
        public ActionResult EditInfo(InfoEditInfoVM model)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            InfoRepository infoRepository = new InfoRepository(unitOfWork);
            Info info = new Info();

            if (infoRepository.GetAll(filter: x => x.Title == model.Title && x.ID != model.ID).FirstOrDefault() != null)
            {
                ModelState.AddModelError("Title", "Article with same name exist");
            }

            model.Title = model.Title.Trim();

            string message = "Successfully created ";

            if (model.ID > 0)
            {
                info = infoRepository.GetByID(model.ID);
                message = "Successfully edited ";
                if (info.Title != model.Title)
                {
                    string filesLocalPath = "~/Content/Files/" + model.Title;
                    if (Directory.Exists(HostingEnvironment.MapPath(filesLocalPath + info.Title)))
                    {
                        Directory.Move(HostingEnvironment.MapPath(filesLocalPath + info.Title),
                                       HostingEnvironment.MapPath(filesLocalPath + model.Title));
                    }
                }
            }

            model.Content = model.Content.Trim();

            info.Content = model.Content;
            info.Title = model.Title;

            infoRepository.Save(info);

            InfoImageRepository infoImageRepository = new InfoImageRepository(unitOfWork);

            HttpFileCollection UploadedFiles = System.Web.HttpContext.Current.Request.Files;

            string filePath = "~/Content/Files/" + model.Title + "/";

            Regex imageRegex = new Regex(ConfigurationManager.AppSettings["ImageRestriction"]);
            Regex fileRegex = new Regex(ConfigurationManager.AppSettings["FileRestriction"]);

            for (int i = 0; i < UploadedFiles.Count; i++)
            {
                if (imageRegex.Match(UploadedFiles[i].FileName).Success)
                {
                    InfoImage infoImage = new InfoImage();

                    infoImage.Name = UploadedFiles[i].FileName;

                    if (infoImageRepository.GetAll(filter: x => x.Name == infoImage.Name && x.InfoID == info.ID).FirstOrDefault() == null)
                    {
                        info.Images = info.Images == null ? info.Images = new List<InfoImage>() : info.Images;
                        info.Images.Add(infoImage);

                        //Create  folder
                        if (!Directory.Exists(HostingEnvironment.MapPath(filePath)))
                            Directory.CreateDirectory(HostingEnvironment.MapPath(filePath));

                        UploadedFiles[i].SaveAs(HostingEnvironment.MapPath(filePath) + UploadedFiles[i].FileName);
                    }
                }
                else if (fileRegex.Match(UploadedFiles[i].FileName).Success)
                {
                    var file = UploadedFiles[i];

                    //Create  folder
                    if (!Directory.Exists(HostingEnvironment.MapPath(filePath)))
                        Directory.CreateDirectory(HostingEnvironment.MapPath(filePath));

                    //If other file is uploaded we delete the old
                    if (info.FileName != null && System.IO.File.Exists(HostingEnvironment.MapPath(filePath + info.FileName)) && file.FileName != info.FileName)
                        System.IO.File.Delete(HostingEnvironment.MapPath(filePath + info.FileName));

                    info.FileName = file.FileName;

                    file.SaveAs(HostingEnvironment.MapPath(filePath) + file.FileName);
                }
            }

            infoRepository.Save(info);
            unitOfWork.Commit();

            AddRemoveKeywords(model.KeywordsInput, info.ID);

            return RedirectToAction("InfoPage", "Info");
        }
        public ActionResult EditInfo(int? id)
        {
            InfoEditInfoVM model = new InfoEditInfoVM();
            InfoRepository infoRepository = new InfoRepository();
            Info info = new Info();

            model.InfoImages = new List<InfoImage>();

            if (id != null)
            {
                info = infoRepository.GetByID(id.Value);

                if (info == null)
                {
                    return RedirectToAction("InfoPage", "Info");
                }

                model.KeywordsInput = string.Empty;

                if (info.Keywords.Count() > 0)
                {
                    model.KeywordsInput = string.Join(", ", info.Keywords.OrderBy(o => o.Value).Select(x => x.Value));
                }

                model.ID = id.Value;
                model.Title = info.Title;
                model.Content = info.Content;
                model.KeywordsInput = string.Join(", ", info.Keywords.OrderBy(o => o.Value).Select(x => x.Value));
                model.InfoImages = info.Images;
                model.FilePath = "/Content/Files/" + model.Title;
            }

            return View(model);
        }
        public ActionResult DeleteInfo(int? id)
        {
            if (id != null)
            {
                InfoRepository InfoRepository = new InfoRepository();
                Info info = InfoRepository.GetByID(id.Value);

                InfoRepository.Delete(info);
                string folderPath = "~/Content/Files/" + info.Title;
                if (Directory.Exists(HostingEnvironment.MapPath(folderPath)))
                    Directory.Delete(HostingEnvironment.MapPath(folderPath), true);
            }

            return RedirectToAction("InfoPage", "Info");
        }
        public JsonResult DeleteFile(int infoid, int imageid)
        {
            InfoRepository infoRepository = new InfoRepository();
            Info info = infoRepository.GetByID(infoid);
            string deleted = string.Empty;

            string filePath = "~/Content/Files/" + info.Title + "/";

            if (imageid > 0)
            {
                deleted = "image";

                InfoImageRepository infoImageRepository = new InfoImageRepository();
                InfoImage infoImage = infoImageRepository.GetByID(imageid);

                infoImageRepository.Delete(infoImageRepository.GetByID(imageid));

                if (infoImage != null && System.IO.File.Exists(HostingEnvironment.MapPath(filePath + infoImage.Name)))
                {
                    System.IO.File.Delete(HostingEnvironment.MapPath(filePath + infoImage.Name));
                }
            }
            return Json(deleted);
        }
Ejemplo n.º 23
0
 public AttractionService(EventRepository eventRepo, AttractionRepository attractionRepo, InfoRepository infoRepo)
 {
     _eventRepo      = eventRepo;
     _attractionRepo = attractionRepo;
     _infoRepo       = infoRepo;
 }
Ejemplo n.º 24
0
 public DriversController(InfoRepository driverInfoRepository)
 {
     _driverInfoRepository = driverInfoRepository;
 }
Ejemplo n.º 25
0
 public RestaurantController(InfoRepository restaurantInfoRepository)
 {
     _restaurantInfoRepository = restaurantInfoRepository;
 }
Ejemplo n.º 26
0
 public < %= extensionName %> InfoController()
 {
     repo = new < %= extensionName % > InfoRepository();
 }
        /// <summary>
        /// This method is called to add or remove Keyword from article
        /// </summary>
        public void AddRemoveKeywords(string keywords, int infoID)
        {
            UnitOfWork unitOfWork = new UnitOfWork();
            KeywordsRepository keywordsRepository = new KeywordsRepository(unitOfWork);
            InfoRepository infoRepository = new InfoRepository(unitOfWork);

            Info info = infoRepository.GetByID(infoID);

            List<int> KeywordsIDList = new List<int>();
            if (keywords != null)
            {
                string[] keywordsArray = keywords.Split(',');

                foreach (var keywordInput in keywordsArray)
                {
                    string value = keywordInput.Trim();
                    value = Regex.Replace(value, @"\s+", " ");

                    Keyword keyword = keywordsRepository.GetAll(filter: x => x.Value == value).FirstOrDefault();

                    if (keyword == null)
                    {
                        if (value != string.Empty)
                        {
                            keyword = new Keyword();
                            keyword.Value = value;
                            keywordsRepository.Save(keyword);

                            KeywordsIDList.Add(keyword.ID);
                        }
                    }
                    else
                    {
                        KeywordsIDList.Add(keyword.ID);
                    }
                }
            }

            List<int> currentArticleKeywordsID = new List<int>();
            info.Keywords = info.Keywords == null ? info.Keywords = new List<Keyword>() : info.Keywords;

            try
            {
                foreach (var item in info.Keywords)
                {
                    currentArticleKeywordsID.Add(item.ID);
                }

                IEnumerable<int> removedKeywordsID = currentArticleKeywordsID.Except(KeywordsIDList);

                foreach (Keyword keyword in info.Keywords.ToList().Where(x => removedKeywordsID.Any(k => k == x.ID)))
                {
                    keyword.Info.Remove(info);
                    keywordsRepository.Save(keyword);
                }

                IEnumerable<int> addKeywordToArticle = KeywordsIDList.Except(currentArticleKeywordsID);

                foreach (var keyID in addKeywordToArticle)
                {
                    Keyword keyword = keywordsRepository.GetByID(keyID);
                    keyword.Info = keyword.Info == null ? new List<Info>() : keyword.Info;
                    keyword.Info.Add(info);

                    keywordsRepository.Save(keyword);
                }
                unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                unitOfWork.RollBack();
                throw ex;
            }
        }
Ejemplo n.º 28
0
 public FoodsController(InfoRepository foodInfoRepository)
 {
     _foodInfoRepository = foodInfoRepository;
 }
Ejemplo n.º 29
0
 public OrdersController(InfoRepository orderInfoRepository)
 {
     _orderInfoRepository = orderInfoRepository;
 }
Ejemplo n.º 30
0
 public OrderedFoodsController(InfoRepository orderedFoodRepository)
 {
     _orderedFoodRepository = orderedFoodRepository;
 }
Ejemplo n.º 31
0
 public HomeController(ProductRepository productRepository, BlogsRepository blogsRepository, InfoRepository infoRepository)
 {
     _infoRepository    = infoRepository;
     _blogsRepository   = blogsRepository;
     _productRepository = productRepository;
 }
        public ActionResult InfoPage()
        {
            InfoInfoPageVM model = new InfoInfoPageVM();
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            this.TryUpdateModel(model);

            InfoRepository infoRepository = new InfoRepository();

            List<Info> filteredInfo = new List<Info>();
            if (model.Search == null)
            {
                filteredInfo = infoRepository.GetAll();
            }
            else
            {
                filteredInfo = infoRepository.GetAll(filter: x => x.Keywords.Any(k => k.Value.Contains(model.Search)));
            }

            model.Search = model.Search == null ? model.Search : model.Search.Trim(' ');

            model.Info = filteredInfo;

            if ((Models.AuthenticationManager.LoggedUser.GetType().Name).Split('_').GetValue(0).ToString() == "Administrator")
            {
                model.CanBeEdited = true;
            }

            return View(model);
        }
Ejemplo n.º 33
0
 public CommonController(InfoRepository infoRep, PartyTaskRepository taskRep)
 {
     _infoRep = infoRep;
     _taskRep = taskRep;
 }
Ejemplo n.º 34
0
Archivo: XML.cs Proyecto: kseniya-rs/c-
 public InfoCar(string connectionString)
 {
     carRepository = new InfoRepository(connectionString);
 }
Ejemplo n.º 35
0
 public CustomersController(InfoRepository customerInfoRepository)
 {
     _customerInfoRepository = customerInfoRepository;
 }