public async Task <IActionResult> PutReligion(short id, Religion religion) { if (id != religion.ReligionId) { return(BadRequest()); } _context.Entry(religion).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReligionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutContactRequest(short id, ContactRequest contactRequest) { if (id != contactRequest.RequestId) { return(BadRequest()); } _context.Entry(contactRequest).State = EntityState.Modified; try { _context.SaveChanges(); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactRequestExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutHairSize(short id, HairSize hairSize) { if (id != hairSize.HairSizeId) { return(BadRequest()); } _context.Entry(hairSize).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HairSizeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutBotCommand(short id, BotCommand botCommand) { if (id != botCommand.Id) { return(BadRequest()); } _context.Entry(botCommand).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BotCommandExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProfil(short id, Profil profil) { if (id != profil.ProfilId) { return(BadRequest()); } _context.Entry(profil).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProfilExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutContactRequest(short id, ContactRequest contactRequest) { if (id != contactRequest.RequestId) { return(BadRequest()); } var detailOldContactRequest = _context.ContactRequests.Where(x => x.RequestId == contactRequest.RequestId).SingleOrDefault(); contactRequest.Id = detailOldContactRequest.Id; contactRequest.RequestDate = detailOldContactRequest.RequestDate; _context.Entry(contactRequest).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactRequestExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutSex(short id, Sex sex) { if (id != sex.SexeId) { return(BadRequest()); } _context.Entry(sex).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SexExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutInsult(int id, Insult insult) { if (id != insult.InsultId) { return(BadRequest()); } _context.Entry(insult).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InsultExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAnswer(short id, Answer answer) { if (id != answer.AnswerId) { return(BadRequest()); } _context.Entry(answer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnswerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UnBan([FromBody] string username) { try { if (username == null) { return(NotFound()); } AspNetUser user = _context.AspNetUsers.Where(d => d.UserName.Equals(username)).Single(); if (user == null) { return(NotFound()); } user.LockoutEnd = null; _context.Entry(user).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok()); } catch (Exception) { return(BadRequest()); } }
public async Task <IActionResult> PutAspNetUser(AspNetUser aspNetUser) { _context.Entry(aspNetUser).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AspNetUserExists(aspNetUser.Id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Index() { var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync(); try { var stripeEvent = EventUtility.ParseEvent(json); // Handle the event if (stripeEvent.Type == Events.PaymentIntentSucceeded) { var paymentIntent = stripeEvent.Data.Object as PaymentIntent; Console.WriteLine("PaymentIntent was successful!"); } else if (stripeEvent.Type == Events.PaymentMethodAttached) { var paymentMethod = stripeEvent.Data.Object as PaymentMethod; Console.WriteLine("PaymentMethod was attached to a Customer!"); } else if (stripeEvent.Type == Events.ChargeSucceeded) { Charge charge = stripeEvent.Data.Object as Charge; short subscriptionId = _LoveMirroringcontext.Subscriptions. Where(s => s.SubscriptionPrice == (charge.Amount / 100)). Select(s => s.SubscriptionId). SingleOrDefault(); UserSubscription subscription = new UserSubscription { UserId = charge.Metadata["UserId"], UserSubscriptionsAmount = charge.Amount / 100, UserSubscriptionsDate = DateTime.Now, SubscriptionsId = subscriptionId }; _LoveMirroringcontext.UserSubscriptions.Add(subscription); await _LoveMirroringcontext.SaveChangesAsync(); } // ... handle other event types else { // Unexpected event type return(BadRequest()); } return(Ok()); } catch (StripeException e) { return(BadRequest()); } }
public async Task <IActionResult> BanUser(string id) { if (id != null) { AspNetUser user = await _context.AspNetUsers.Where(u => u.UserName == id).FirstOrDefaultAsync(); user.LockoutEnd = new DateTimeOffset(new DateTime(2400, 05, 03)); _context.Entry(user).State = EntityState.Modified; await _context.SaveChangesAsync(); return(StatusCode(200)); } else { return(StatusCode(404)); } }
public async Task <IActionResult> CreateMessage(Message message) { if (message == null) { return(BadRequest()); } else { if (message.MessageText != "") { message.MessageDate = DateTime.Now; _context.Messages.Add(message); await _context.SaveChangesAsync(); } return(Ok()); } }
public async Task <IActionResult> Like([FromBody] string username) { string accessToken = await HttpContext.GetTokenAsync("access_token"); AspNetUser user = null; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); string userString = await client.GetStringAsync(Configuration["URLAPI"] + "api/Account/getUserInfo"); user = JsonConvert.DeserializeObject <AspNetUser>(userString); UserLike ul = new UserLike(); AspNetUser userLiked = _context.AspNetUsers.Where(d => d.UserName == username).Single(); ul.Id = user.Id; ul.Id1 = userLiked.Id; ul.Ignored = false; try { //cherche si il existe une conversation entre les deux personnes Talk talk = _context.Talks.Where(t => t.Id == user.Id && t.IdUser2Talk == userLiked.Id).SingleOrDefault(); if (talk == null) { talk = _context.Talks.Where(t => t.Id == userLiked.Id && t.IdUser2Talk == user.Id).SingleOrDefault(); } //crée une conversation si la conversation n'existe pas if (talk == null) { Talk newtalk = new Talk { Id = user.Id, IdUser2Talk = userLiked.Id, TalkName = user.NormalizedUserName + userLiked.NormalizedUserName }; _context.Talks.Add(newtalk); await _context.SaveChangesAsync(); } _context.UserLikes.Add(ul); _context.SaveChanges(); return(Ok()); } catch (Exception) { return(BadRequest()); } }
public async Task <IActionResult> PutAd(short id, AdPost adPost) { if (id != adPost.Id) { return(BadRequest()); } string folder = "Ads"; AdInput ad = new AdInput(); ad.Id = adPost.Id; ad.Titre = adPost.Titre; ad.Description = adPost.Description; ad.Link = adPost.Link; byte[] data = Convert.FromBase64String(adPost.file); var stream = new MemoryStream(data); IFormFile file = new FormFile(stream, 0, data.Length, adPost.name, adPost.fileName) { Headers = new HeaderDictionary(), ContentType = adPost.ContentType, ContentDisposition = adPost.ContentDisposition }; ad.file = file; if (ad.file.Length > 0) { if (!Directory.Exists(Path.Combine(_environnement.WebRootPath, folder))) { Directory.CreateDirectory(Path.Combine(_environnement.WebRootPath, folder)); } string filename = "_ad" + DateTime.Now.ToString("_yyyy-MM-dd_HH-mm-ss_") + ad.file.FileName; using (FileStream fileStream = System.IO.File.Create(Path.Combine(_environnement.WebRootPath, folder, filename))) { ad.file.CopyTo(fileStream); fileStream.Flush(); _context.Entry(new Ad { Id = ad.Id, Titre = ad.Titre, Description = ad.Description, AdView = folder + "/" + filename, Link = ad.Link }).State = EntityState.Modified; } } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }