Пример #1
0
        public async Task <ActionResult <PhotoDto> > AddPhoto(IFormFile file, int id)
        {
            var existingEvent = await _eventsRepository.GetEventByIdAsync(id);

            var result = await _photoService.AddPhotoAsync(file);

            if (result.Error != null)
            {
                return(BadRequest(result.Error.Message));
            }

            var photo = new EventPhoto
            {
                Url      = result.SecureUrl.AbsoluteUri,
                publicId = result.PublicId
            };

            if (existingEvent.Photos.Count == 0)
            {
                photo.MainPhoto            = true;
                existingEvent.MainPhotoUrl = photo.Url;
            }

            existingEvent.Photos = existingEvent.Photos ?? new List <EventPhoto>();
            existingEvent.Photos.Add(photo);

            if (await _eventsRepository.SaveAllAsync())
            {
                return(CreatedAtRoute("GetEvent", new { id = existingEvent.Id }, _mapper.Map <EventPhoto, PhotoDto>(photo)));
            }

            return(BadRequest("Unable to upload photo"));
        }
        public async Task <HttpResponseMessage> SendRequestAsync_jw(EventPhoto x12345, EventUser x)
        {
            using (var client12 = new HttpClient())
            {
                client12.Timeout = TimeSpan.FromSeconds(200);

                // Set the Accept header for BSON.
                client12.DefaultRequestHeaders.Accept.Clear();
                client12.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));
                client12.BaseAddress = new Uri(App.UrlStart + "Event/AddPhoto/");
                client12.DefaultRequestHeaders.Authorization
                    = new AuthenticationHeaderValue("basic", x.SecretPassword + " " + x.qrcode);

                ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain, errors) => true;

                //  StringContent content12 = new StringContent(ImageData, Encoding.UTF8, "application/bson");
                var content = new StringContent(JsonConvert.SerializeObject(x12345), Encoding.UTF8, "application/json");
                // POST using the BSON formatter.
                //MediaTypeFormatter bsonFormatter = new BsonMediaTypeFormatter();
                var result = await client12.PostAsync("aaa", content);

                if (result.IsSuccessStatusCode)
                {
                    string resultContent = await result.Content.ReadAsStringAsync();

                    conn = DependencyService.Get <ISQLite>().GetConnection();
                    conn.CreateTable <EventPhoto>();
                    x12345.EventPhotoId = Convert.ToInt32(resultContent);
                    conn.Update(x12345);
                }
            }
            return(null);
        }
        protected async Task <string> MyMethod(MainWindow mainWindow)
        {
            conn = DependencyService.Get <ISQLite>().GetConnection();


            List <EventPhoto> query = conn.Query <EventPhoto>("Select * From EventPhoto where EventPhotoId =0  ORDER BY ROWID ASC LIMIT 1");

            if (query.Count > 0)
            {
                EventPhoto EP = query[0];

                conn = DependencyService.Get <ISQLite>().GetConnection();
                conn.CreateTable <EventUser>();

                EventUser a = conn.Table <EventUser>().Where(k => k.EventId == EP.EventId).ToList()[0];

                var x12356 = await SendRequestAsync_jw(EP, a);
            }
            return(null);
        }
Пример #4
0
        void enterintoEvent()
        {
            try
            {
                string filename;
                string path = Server.MapPath("~/eventphotos/");
                filename = "no photo";
                if (EventPhoto.HasFile)
                {
                    filename = "~/eventphotos/" + EventPhoto.FileName;

                    EventPhoto.SaveAs(path + EventPhoto.FileName);
                }
                SqlConnection CompCon = new SqlConnection(ConfigurationManager.ConnectionStrings["EventsConnectionString"].ConnectionString);

                SqlCommand inData = new SqlCommand("INSERT INTO Event(EventID,GameID,FeatureEvent,EventVenue,EventDate,EventStartTime,EventEndTime,EventDescription,WorldRecord) VALUES (@EventID,@GameID,@Feature,@Venue,@Date,@Start,@End,@Description,@Record)", CompCon);
                inData.Parameters.AddWithValue("@EventId", EventID.Text);
                inData.Parameters.AddWithValue("@GameID", GameIDList.SelectedValue);
                inData.Parameters.AddWithValue("@Feature", FeatureEvent.Text);
                inData.Parameters.AddWithValue("@Venue", EventVenue.Text);
                inData.Parameters.AddWithValue("@Date", EventDate.Text);
                inData.Parameters.AddWithValue("@Start", EventStartTime.Text);
                inData.Parameters.AddWithValue("@End", EventEndTime.Text);
                inData.Parameters.AddWithValue("@Description", EventDescription.Text);
                inData.Parameters.AddWithValue("@Record", WorldRecord.Text);

                SqlCommand inPlay = new SqlCommand("INSERT INTO PHOTO(EventPhoto,EventPhotoTags,EventID) VALUES (@Photo, @Tags,@EventID)", CompCon);
                inPlay.Parameters.AddWithValue("@Photo", filename);
                inPlay.Parameters.AddWithValue("@Tags", PhotoTags.Text);
                inPlay.Parameters.AddWithValue("@EventID", EventID.Text);
                CompCon.Open();
                inData.ExecuteNonQuery();
                inPlay.ExecuteNonQuery();
                CompCon.Close();
                Response.Redirect("~/EventManager.aspx");
            }
            catch (Exception ex)
            {
            }
        }
Пример #5
0
        public void ImagesUpload(int id)
        {
            MafiaContext context = new MafiaContext();
            Event        evt     = context.Events.Find(id);

            if (!string.IsNullOrEmpty(Request.Headers["X-File-Name"]))
            {
                String serverPath  = string.Format("/Uploads/{0}", Request.Headers["X-File-Name"]);
                string path        = Server.MapPath(serverPath);
                Stream inputStream = Request.InputStream;
                using (FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate))
                {
                    inputStream.CopyTo(fileStream);
                    fileStream.Close();
                }
                EventPhoto evtPh = new EventPhoto()
                {
                    ParentEvent = evt,
                    Path        = serverPath
                };
                context.EventPhotos.Add(evtPh);
                context.SaveChanges();
            }
        }
        private async void Button_Clicked(object sender, EventArgs e)
        {
            var action = await DisplayActionSheet("Dodaj zdjęcie do wydarzenia", "Anuluj", null, "Wybierz istniejące", "Zrób zdjęcie");

            MediaFile        file  = null;
            List <MediaFile> files = new List <MediaFile>();

            if (action == "Zrób zdjęcie")
            {
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");

                    return;
                }
                file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    Directory = "Sample",
                    Name      = "test.jpg"
                });
            }
            if (action == "Wybierz istniejące")
            {
                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("Photos Not Supported", "Permission not granted to photos", "OK");

                    return;
                }
                files = await Plugin.Media.CrossMedia.Current.PickPhotosAsync(new
                                                                              Plugin.Media.Abstractions.PickMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Full
                });
            }

            if (files.Count == 0 && file != null)
            {
                files.Add(file);
            }

            if (files.Count == 0)
            {
                if (file == null)
                {
                    return;
                }
            }
            if (files.Count > 0)
            {
                foreach (MediaFile mf in files)
                {
                    byte[] aaaa;
                    Stream aaaaaaaa;

                    using (var memoryStream = new MemoryStream())
                    {
                        mf.GetStream().CopyTo(memoryStream);
                        mf.Dispose();
                        aaaaaaaa = memoryStream;
                        aaaa     = memoryStream.ToArray();
                    }


                    EventUser stringInThisCell = (EventUser)((Button)sender).BindingContext;

                    conn = DependencyService.Get <ISQLite>().GetConnection();
                    conn.CreateTable <EventPhoto>();

                    EventPhoto x = new EventPhoto();
                    x.PhotoOriginal = aaaa;
                    var balbal = DependencyService.Get <IMediaService>().ResizeImage(aaaa, 200, 200);
                    x.Photo        = balbal;
                    x.DateAdded    = DateTime.Now;
                    x.EventUserId  = stringInThisCell.EventUserID;
                    x.EventId      = stringInThisCell.EventId;
                    x.EventPhotoId = 0;
                    conn.Insert(x);
                }
            }
        }