Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Launch WCF server...");
            MyPhotos host = new MyPhotos(typeof(MyPhotos), new Uri("http://localhost:8000/WindowsFormsMyPhotos"));

            foreach (ServiceEndpoint se in host.Description.Endpoints)
            {
                Console.WriteLine("A (address): {0} \nB (binding): {1} \nC(Contract): {2}\n", se.Address, se.Binding.Name, se.Contract.Name);
            }

            host.Open();

            Console.WriteLine("Server in execution. Connections are expected...");
            Console.WriteLine("Press Enter to stop the server!");
            Console.ReadKey();

            host.Close();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,PhotoName,Url,Date")] MyPhotos myPhotos)
        {
            if (id != myPhotos.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(myPhotos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(myPhotos));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,PhotoName,ImageFile,Date")] MyPhotos myPhotos)
        {
            if (ModelState.IsValid)
            {
                String wwwRootPath  = _hostEnvironment.WebRootPath;
                string fileName     = Path.GetFileNameWithoutExtension(myPhotos.ImageFile.FileName);
                string extensioName = Path.GetExtension(myPhotos.ImageFile.FileName);
                myPhotos.PhotoName = fileName = fileName + extensioName;
                string path = Path.Combine(wwwRootPath + "/Image/", fileName);
                myPhotos.Url   = path;
                myPhotos.Email = @User.Identity.Name;
                using (var fileStream = new FileStream(path, FileMode.Create)) {
                    await myPhotos.ImageFile.CopyToAsync(fileStream);
                }



                _context.Add(myPhotos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(myPhotos));
        }