public ActionResult Delete(int id) { SocialMediaAccount mediaAccount = socialMediaAccountService.GetByID(id); socialMediaAccountService.Remove(mediaAccount); return(Redirect("/SysAdmin/SocialMedia/List")); }
public object Any(Services.SetSocialMediaAccount request) { SocialMediaPlatform platform = null; try { platform = SocialMediaPlatform.FromDisplayName <SocialMediaPlatform>(request.Platform); } catch { return(string.Format("Please use one of those platforms {0}", string.Join(',', SocialMediaPlatform.GetAll <SocialMediaPlatform>().Select(w => w.Name)))); } var socialMediaAccount = dbContext.SocialMediaAccounts.Where(sm => sm.PlatformId == platform.Id).SingleOrDefault(); if (socialMediaAccount == null) { socialMediaAccount = new SocialMediaAccount() { PlatformId = platform.Id, Username = request.Username }; socialMediaAccount.Version = 1; dbContext.SocialMediaAccounts.Add(socialMediaAccount); dbContext.SaveChanges(); return(true); } socialMediaAccount.Username = request.Username; dbContext.SaveChanges(); return(true); }
public void DeleteSocialMediaAccount(int foodTruckId, int socialMediaPlatformId) { var foodTruck = _foodTruckRepository.GetFoodTruck(foodTruckId); if (foodTruck == null) { throw new ObjectNotFoundException("No food truck with the id of {foodTruckId} could be found"); } var platform = _socialMediaPlatformRepository.GetSocialMediaPlatform(socialMediaPlatformId); if (platform == null) { throw new ObjectNotFoundException($"No social media platform with the id {socialMediaPlatformId} could be found"); } SocialMediaAccount account = foodTruck.SocialMediaAccounts.FirstOrDefault(a => a.PlatformId == socialMediaPlatformId); if (account == null) { throw new ObjectNotFoundException($"No social media account with for {platform.Name} could be found on the food truck with id {foodTruckId}"); } foodTruck.RemoveSocialMediaAccount(account); // Persist to the database _foodTruckRepository.Save(foodTruck); UnitOfWork.SaveChanges(); return; }
public SocialMediaAccount AddSocialMediaAccount(int foodTruckId, int socialMediaPlatformId, string accountName) { var foodTruck = _foodTruckRepository.GetFoodTruck(foodTruckId); if (foodTruck == null) { throw new ObjectNotFoundException("No food truck with the id of {foodTruckId} could be found"); } var platform = _socialMediaPlatformRepository.GetSocialMediaPlatform(socialMediaPlatformId); if (platform == null) { throw new ObjectNotFoundException("No social media platform with the id {socialMediaPlatformId} could be found"); } SocialMediaAccount account = new SocialMediaAccount(platform, foodTruck, accountName); foodTruck.AddSocialMediaAccount(account); // Persist to the database _foodTruckRepository.Save(foodTruck); UnitOfWork.SaveChanges(); return(account); }
public async Task <ActionResult <SocialMediaAccountDto> > PutSocialMediaAccount([FromRoute] int id, [FromBody] SocialMediaAccountDto socialMediaAccountDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != socialMediaAccountDto.ID) { return(BadRequest()); } SocialMediaAccount socialMediaAccount = DtoToEntityIMapper.Map <SocialMediaAccountDto, SocialMediaAccount>(socialMediaAccountDto); repository.ModifyEntryState(socialMediaAccount, EntityState.Modified); try { await uoW.SaveAsync(); } catch (DbUpdateConcurrencyException) { if (!SocialMediaAccountExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public Result <FoodTruck> CreateFoodTruck(CreateFoodTruckCommand foodTruckInfo) { // Creates our Food Truck object var foodTruck = new FoodTruck(foodTruckInfo.Name, foodTruckInfo.Description, foodTruckInfo.Website); // Converts tag strings into tag objects (including creating tags that don't exist) var tagObjects = DecodeTags(foodTruckInfo.Tags); // Attaches the tags to the Food Truck Object tagObjects.ForEach(obj => foodTruck.AddTag(obj)); // Social Media Accounts foreach (var accountInfo in foodTruckInfo.SocialMediaAccounts) { var platform = _socialMediaPlatformRepository.GetSocialMediaPlatform(accountInfo.SocialMediaPlatformId); if (platform == null) { throw new InvalidDataException($"The id {accountInfo.SocialMediaPlatformId} is not a valid social media platform id"); } SocialMediaAccount account = new SocialMediaAccount(platform, foodTruck, accountInfo.AccountName); foodTruck.AddSocialMediaAccount(account); } // Persist to the database _foodTruckRepository.Save(foodTruck); UnitOfWork.SaveChanges(); return(Result.Success <FoodTruck>(foodTruck)); }
public Result <SocialMediaAccount> AddSocialMediaAccount(int foodTruckId, int socialMediaPlatformId, string accountName) { var foodTruck = _foodTruckRepository.GetFoodTruck(foodTruckId); if (foodTruck == null) { return(Result.Failure <SocialMediaAccount>(new ObjectNotFoundError("No food truck with the id of {foodTruckId} could be found"))); } var platform = _socialMediaPlatformRepository.GetSocialMediaPlatform(socialMediaPlatformId); if (platform == null) { return(Result.Failure <SocialMediaAccount>(new InvalidDataError("No social media platform with the id {socialMediaPlatformId} could be found"))); } SocialMediaAccount account = new SocialMediaAccount(platform, foodTruck, accountName); foodTruck.AddSocialMediaAccount(account); // Persist to the database _foodTruckRepository.Save(foodTruck); UnitOfWork.SaveChanges(); return(Result.Success <SocialMediaAccount>(account)); }
public ActionResult CreateAccount(int id) { SocialMediaAccount account = new SocialMediaAccount(); account.AppInfoId = id; return(View(account)); }
public ActionResult Update(SocialMediaDTO mediaDTO) { SocialMediaAccount mediaAccount = socialMediaAccountService.GetByID(mediaDTO.ID); mediaAccount.Name = mediaDTO.Name; mediaAccount.Url = mediaDTO.Url; socialMediaAccountService.Update(mediaAccount); return(Redirect("/SysAdmin/SocialMedia/List")); }
public ActionResult Edit([Bind(Include = "Id,Facebook,Twitter,Linkedin,Github,Youtube")] SocialMediaAccount socialMediaAccount) { if (ModelState.IsValid) { db.Entry(socialMediaAccount).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(socialMediaAccount)); }
public static TModel FromSocialMediaAccount <TModel>(SocialMediaAccount socialMediaAccount) where TModel : SocialMediaAccountApiModel, new() { var model = new TModel(); model.Id = socialMediaAccount.Id; model.TenantId = socialMediaAccount.TenantId; model.Name = socialMediaAccount.Name; return(model); }
public ActionResult Update(int id) { SocialMediaAccount mediaAccount = socialMediaAccountService.GetByID(id); SocialMediaDTO mediaDTO = new SocialMediaDTO() { ID = mediaAccount.ID, Name = mediaAccount.Name, Url = mediaAccount.Url, }; return(View(mediaDTO)); }
public async Task <IHttpActionResult> GetSocialMediaAccount(int id) { SocialMediaAccount item = await UoW.GetRepository <SocialMediaAccount>().GetItemAsycn(e => e.ID == id); if (item == null) { return(NotFound()); } var DTO = EntityToDtoIMapper.Map <SocialMediaAccount, SocialMediaAccountDto>(item); return(Ok(DTO)); }
// GET: SocialMediaAccounts/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SocialMediaAccount socialMediaAccount = db.SocialMediaAccount.Find(id); if (socialMediaAccount == null) { return(HttpNotFound()); } return(View(socialMediaAccount)); }
public async Task <ActionResult <SocialMediaAccountDto> > PostSocialMediaAccount([FromBody] SocialMediaAccountDto socialMediaAccountDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } SocialMediaAccount socialMediaAccount = DtoToEntityIMapper.Map <SocialMediaAccountDto, SocialMediaAccount>(socialMediaAccountDto); repository.Add(socialMediaAccount); await uoW.SaveAsync(); return(CreatedAtAction("GetSocialMediaAccount", new { id = socialMediaAccount.ID }, socialMediaAccountDto)); }
public async Task <IHttpActionResult> DeleteSocialMediaAccount(int id) { SocialMediaAccount socialMediaAccount = await UoW.GetRepository <SocialMediaAccount>().GetItemAsycn(e => e.ID == id); if (socialMediaAccount == null) { return(NotFound()); } UoW.GetRepository <SocialMediaAccount>().Delete(socialMediaAccount); await UoW.SaveAsync(); return(Ok(socialMediaAccount)); }
public static void Main(string[] args) { SocialMediaAccount timothy = new SocialMediaAccount(); timothy.Login = "******"; timothy.Email = "*****@*****.**"; // timothy.IsActive = true; // cannot access private component timothy.Display(); System.Console.WriteLine(); timothy.AddConnection(100); System.Console.WriteLine("Has connections: " + timothy.HasConnections()); System.Console.WriteLine("Is ID 100 a friend? " + timothy.IsFriend(100)); System.Console.WriteLine("Is ID 100 a friend? " + timothy.IsFriend(200)); }
IEnumerator RandomBreweryRequest() { // Consultar la base de datos de cervecerias UnityWebRequest www = UnityWebRequest.Get("https://sandbox-api.brewerydb.com/v2/brewery/random/?key=c18b053c1490e5a8d2593a9586913cb7&withSocialAccounts=Y"); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { // Si ocurre un error escribirlo en la consola Debug.Log(www.error); } else { // Si no hay error leer el resultado en formato json y mostrar los datos relevantes en pantalla Debug.Log(www.downloadHandler.text); var jsonSerializer = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer); var result = jsonSerializer.DeserializeObject <Dictionary <string, object> >(www.downloadHandler.text); var data = result["data"] as JsonObject; // Mostrar el nombre de la cerveceria Debug.Log(data["name"] as string); breweryNameText.text = data["name"] as string; // Borrar los anteriores links a redes sociales foreach (Transform t in socialMediaContainer) { Destroy(t.gameObject); } // Si la nueva cerveceria tiene redes sociales, mostrar los links if (data.Keys.Contains("socialAccounts")) { var socialAccounts = data["socialAccounts"] as JsonArray; foreach (JsonObject socialAccount in socialAccounts) { if (socialAccount.Keys.Contains("link")) { Debug.Log(socialAccount["link"]); SocialMediaAccount newSocialMediaAccount = Instantiate(socialMediaAccountPrefab, socialMediaContainer); newSocialMediaAccount.link.text = socialAccount["link"] as string; } } } } }
public ActionResult DeleteAccount(int id) { SocialMediaAccount account = _context.SocialMediaAccounts.Find(id); int appInfoId = account.AppInfoId; _context.SocialMediaAccounts.Remove(account); _context.SaveChanges(); AppInfo appInfo = _context.AppInfo.Find(appInfoId); if (appInfo.Name == "About Application") { return(RedirectToAction("AboutApplication")); } else { return(RedirectToAction("AboutOwner")); } }
public async Task <ActionResult <SocialMediaAccountDto> > DeleteSocialMediaAccount([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } SocialMediaAccount socialMediaAccount = await repository.GetAsync(a => a.ID == id); if (socialMediaAccount == null) { return(NotFound()); } repository.Delete(socialMediaAccount); await uoW.SaveAsync(); SocialMediaAccountDto socialMediaAccountDto = EntityToDtoIMapper.Map <SocialMediaAccount, SocialMediaAccountDto>(socialMediaAccount); return(Ok(socialMediaAccountDto)); }
public ActionResult CreateAccount(IFormCollection collection) { SocialMediaAccount account = new SocialMediaAccount(); account.Name = collection["Name"]; account.Link = collection["Link"]; account.AppInfoId = Int32.Parse(collection["AppInfoId"]); _context.Add(account); _context.SaveChanges(); AppInfo temp = _context.AppInfo.Find(account.AppInfoId); if (temp.Name == "About Application") { return(RedirectToAction("AboutApplication")); } else { return(RedirectToAction("AboutOwner")); } }
public ActionResult EditAccount(int id, IFormCollection collection) { SocialMediaAccount account = _context.SocialMediaAccounts.Find(id); int appInfoId = account.AppInfoId; account.Name = collection["Name"]; account.Link = collection["Link"]; _context.Update(account); _context.SaveChanges(); AppInfo appInfo = _context.AppInfo.Find(appInfoId); if (appInfo.Name == "About Application") { return(RedirectToAction("AboutApplication")); } else { return(RedirectToAction("AboutOwner")); } }
public FoodTruck CreateFoodTruck(CreateFoodTruckCommand foodTruckInfo) { try { // Creates our Food Truck object var foodTruck = new FoodTruck(foodTruckInfo.Name, foodTruckInfo.Description, foodTruckInfo.Website); // Converts tag strings into tag objects (including creating tags that don't exist) var tagObjects = DecodeTags(foodTruckInfo.Tags); // Attaches the tags to the Food Truck Object tagObjects.ForEach(obj => foodTruck.AddTag(obj)); // Social Media Accounts foreach (var accountInfo in foodTruckInfo.SocialMediaAccounts) { var platform = _socialMediaPlatformRepository.GetSocialMediaPlatform(accountInfo.SocialMediaPlatformId); if (platform == null) { throw new InvalidDataException($"The id {accountInfo.SocialMediaPlatformId} is not a valid social media platform id"); } SocialMediaAccount account = new SocialMediaAccount(platform, foodTruck, accountInfo.AccountName); foodTruck.AddSocialMediaAccount(account); } // Persist to the database _foodTruckRepository.Save(foodTruck); UnitOfWork.SaveChanges(); return(foodTruck); } catch (Exception ex) { Logger.LogError(new EventId(104), ex, $"Error thrown while calling FoodTruckService.CreateFoodTruck()"); throw; } }
public SocialMediaAccount UpdateSocialMediaAccount(int foodTruckId, int socialMediaAccountId, string accountName) { var foodTruck = _foodTruckRepository.GetFoodTruck(foodTruckId); if (foodTruck == null) { throw new ObjectNotFoundException($"No food truck with the id of {foodTruckId} could be found"); } SocialMediaAccount account = foodTruck.SocialMediaAccounts.FirstOrDefault(a => a.SocialMediaAccountId == socialMediaAccountId); if (account == null) { throw new ObjectNotFoundException($"No social media account with with the id {socialMediaAccountId} could be found on the food truck with id {foodTruckId}"); } account.AccountName = accountName; // Persist to the database _foodTruckRepository.Save(foodTruck); UnitOfWork.SaveChanges(); return(account); }
public Result <SocialMediaAccount> UpdateSocialMediaAccount(int foodTruckId, int socialMediaAccountId, string accountName) { var foodTruck = _foodTruckRepository.GetFoodTruck(foodTruckId); if (foodTruck == null) { return(Result.Failure <SocialMediaAccount>(new ObjectNotFoundError("No food truck with the id of {foodTruckId} could be found"))); } SocialMediaAccount account = foodTruck.SocialMediaAccounts.FirstOrDefault(a => a.SocialMediaAccountId == socialMediaAccountId); if (account == null) { return(Result.Failure <SocialMediaAccount>(new ObjectNotFoundError($"No social media account with with the id {socialMediaAccountId} could be found on the food truck with id {foodTruckId}"))); } account.AccountName = accountName; // Persist to the database _foodTruckRepository.Save(foodTruck); UnitOfWork.SaveChanges(); return(Result.Success <SocialMediaAccount>(account)); }
public static SocialMediaAccountApiModel FromSocialMediaAccount(SocialMediaAccount socialMediaAccount) => FromSocialMediaAccount <SocialMediaAccountApiModel>(socialMediaAccount);
public ActionResult EditAccount(int id) { SocialMediaAccount account = _context.SocialMediaAccounts.Find(id); return(View(account)); }
public ActionResult Add(SocialMediaAccount mediaAccount) { mediaAccount.UserID = userService.GetByDefault(X => X.UserName == User.Identity.Name).ID; socialMediaAccountService.Add(mediaAccount); return(Redirect("/SysAdmin/SocialMedia/List")); }