Esempio n. 1
0
        public IActionResult PhotoTag()
        {
            var people = this.AllPeople;
            var photos = this.AllPhotos;

            var vm = new PhotoTagViewModel
            {
                People = people,
                Photos = photos
            };

            return(View(vm));
        }
Esempio n. 2
0
        public async Task <IActionResult> Get([FromBody] List <String> photoids)
        {
            if (photoids.Count <= 0)
            {
                return(BadRequest("No photo list"));
            }

            List <PhotoTagViewModel> listRst = new List <PhotoTagViewModel>();

            using (SqlConnection conn = new SqlConnection(Startup.DBConnectionString))
            {
                String strsql = @"SELECT [PhotoID],[Tag] FROM [dbo].[PhotoTag] WHERE [PhotoID] IN (";

                for (Int32 i = 0; i < photoids.Count; i++)
                {
                    strsql += "N'" + photoids[i] + "'";
                    if (i != photoids.Count - 1)
                    {
                        strsql += ", ";
                    }
                }
                strsql += ") ";

                await conn.OpenAsync();

                SqlCommand    cmd    = new SqlCommand(strsql, conn);
                SqlDataReader reader = await cmd.ExecuteReaderAsync();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        PhotoTagViewModel vm = new PhotoTagViewModel();
                        vm.PhotoId   = reader.GetString(0);
                        vm.TagString = reader.GetString(1);
                        listRst.Add(vm);
                    }
                }

                reader.Close();
                reader = null;
                cmd.Dispose();
                cmd = null;
            }

            return(new JsonResult(listRst));
        }
Esempio n. 3
0
        public IActionResult PhotoTag(PhotoTagViewModel viewModel)
        {
            var personPhoto = new PersonPhoto
            {
                PersonId = viewModel.PersonId,
                PhotoId  = viewModel.PhotoId
            };

            Db.Insert(personPhoto);

            viewModel.People   = this.AllPeople;
            viewModel.Photos   = this.AllPhotos;
            viewModel.PersonId = 0;
            viewModel.PhotoId  = 0;

            return(View(viewModel));
        }