public async Task <IActionResult> PutCollection(int id, Collection collection) { if (id != collection.midex) { return(BadRequest()); } _context.Entry(collection).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CollectionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCard([FromRoute] int id, [FromBody] Card card) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != card.CardId) { return(BadRequest()); } _context.Entry(card).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CardExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutActor(int id, Actor actor) { if (id != actor.Id) { return(BadRequest()); } _context.Entry(actor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> PutPiece(int id, Piece piece) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != piece.PieceId) { return(BadRequest()); } db.Entry(piece).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PieceExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> Create([Bind("ArtistId,Name")] Artist artist) { if (ModelState.IsValid) { _context.Add(artist); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(artist)); }
public async Task <IActionResult> Create([Bind("LendingId,Name,Date,RecordId")] Lending lending) { if (ModelState.IsValid) { _context.Add(lending); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RecordId"] = new SelectList(_context.Records, "RecordId", "Name", lending.RecordId); return(View(lending)); }
public async Task <IActionResult> Create([Bind("RecordId,Name,Year,ArtistId")] Record @record) { if (ModelState.IsValid) { _context.Add(@record); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ArtistId"] = new SelectList(_context.Artists, "ArtistId", "ArtistId", @record.ArtistId); return(View(@record)); }
public async Task <IActionResult> Create([Bind("CdID,Name,ReleaseYear,ArtistID")] Cd cd) { if (ModelState.IsValid) { _context.Add(cd); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ArtistID"] = new SelectList(_context.Artist, "ArtistID", "Name", cd.ArtistID); return(View(cd)); }
public async Task <ActionResult> CollectionCreate(string userName, string Title, string Theme, string Description, string ShortDescription, string ImageUrl) { User User = await _userManager.FindByNameAsync(userName); string[] integers = Request.Form["Int"]; string[] strings = Request.Form["Str"]; string[] dates = Request.Form["Date"]; string[] booles = Request.Form["Bool"]; string[] texts = Request.Form["Text"]; for (int i = 0; i < booles.Length; i++) { if (booles[i] == "$$$$$") { booles[i] = "Incorrect name"; } } Dictionary <string, string[]> dictionary = new Dictionary <string, string[]> { ["int"] = integers, ["str"] = strings, ["date"] = dates, ["bool"] = booles, ["text"] = texts }; string description = markdown.Transform(Description); string title = markdown.Transform(Title); Collection collection = new Collection { Id = Guid.NewGuid().ToString(), UserName = User.UserName, UserId = User.Id, nItems = 0, Title = title, Theme = Theme, Description = description, ShortDescription = ShortDescription, Fields = JsonSerializer.Serialize(dictionary), Img = ImageUrl, Type = "Collection", Date = DateTime.Now }; User.nCollections++; await _userManager.UpdateAsync(User); await _collectionContext.Collections.AddAsync(collection); await _collectionContext.SaveChangesAsync(); return(RedirectToAction("Collection", "Collection", new{ userName = userName, collectionId = collection.Id })); }
public async Task <IActionResult> Create(CreateViewModel model) { if (User.Identity.Name == null) { return(RedirectToAction("Login", "Account")); } else { if (ModelState.IsValid) { Collection collection = new Collection { UserName = model.UserName, CollectionName = model.CollectionName, CreationDate = model.CreationDate, Likes = model.Likes, Text = model.Text, }; if (model.Image != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(model.Image.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)model.Image.Length); } collection.Image = imageData; } db.Collections.Add(collection); await db.SaveChangesAsync(); return(RedirectToAction("Index", "Collections", new { userName = model.UserName })); } else { return(View(model)); } } }
public async Task <ActionResult> ItemCreate(string collectionId, string Title, string Description, string ShortDescription, string exitionalString, string Tags, bool goToNew, string ImageUrl) { Collection collection = _collectionContext.Collections .Where(o => o.Id == collectionId) .FirstOrDefault(); User user = await _userManager.FindByNameAsync(collection.UserName); Dictionary <string, string[]> CollectionFields = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(collection.Fields); Dictionary <string, string> ItemFields = new Dictionary <string, string>(); //var markdown = new MarkdownSharp.Markdown(); foreach (var colStr in CollectionFields) { string type = colStr.Key; foreach (var colName in colStr.Value) { string name = colName; string value = Request.Form[name]; if (value == "" || value == null) { value = "off"; } string s = type + "$$$$$" + markdown.Transform(value); ItemFields.Add(markdown.Transform(name), s); } } string html = markdown.Transform(Description); string title = markdown.Transform(Title); Item item = new Item { Id = Guid.NewGuid().ToString(), CollectionId = collectionId, UserName = collection.UserName, Title = title, Description = html, Tags = Tags, CollectionName = collection.Title, ImageUrl = ImageUrl, OptionalFields = JsonConvert.SerializeObject(ItemFields), nComments = 0, nLikes = 0, Type = "Item", Date = DateTime.Now }; List <Tag> Tagss = _tagContext.Tags.ToList(); string[] ListTag = Tags.Split(" "); foreach (var tag in ListTag) { var result = _tagContext.Tags.Where(o => o.Text == tag).SingleOrDefault(); if (result == null) { Tag Tag = new Tag() { Id = Guid.NewGuid().ToString(), Text = tag }; _tagContext.Add(Tag); } ; } await _tagContext.SaveChangesAsync(); _itemContext.Add(item); collection.nItems++; user.nItems++; await _userManager.UpdateAsync(user); await _collectionContext.SaveChangesAsync(); await _itemContext.SaveChangesAsync(); if (goToNew == true) { return(RedirectToAction("Create", "Item", new { collectionId = collection.Id })); } return(RedirectToAction("Collection", "Collection", new { collectionId = collection.Id })); }