// PUT api/tagapi/5 public HttpResponseMessage Put(int id, Tag genre) { try { var genreToUpdate = unitOfWork.TagRepository.GetByID(id); genreToUpdate.Name = genre.Name; unitOfWork.TagRepository.Update(genreToUpdate); unitOfWork.Save(); return Request.CreateResponse(HttpStatusCode.OK); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); } }
private void EditATag(Tag model) { var tagToUpdate = unitOfWork.TagRepository.GetByID(model.ID); tagToUpdate.Name = model.Name; unitOfWork.TagRepository.Update(tagToUpdate); unitOfWork.Save(); }
public ActionResult EditTag(Tag model) { try { if (ModelState.IsValid) { EditATag(model); return RedirectToAction("Tags", "Admin"); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again."); } catch (Exception) { ModelState.AddModelError("", "Tga with the same name is already exists."); } return View(model); }
private void SetTags(string tagString, Photo photo) { IEnumerable<string> tags = TagService.SplitTags(tagString).Distinct(); if (photo.Tags != null) { photo.Tags.Clear(); } else { photo.Tags = new List<Tag>(); } foreach (var tag in tags) { var tmp = unitOfWork.TagRepository.GetTagByName(tag.Trim()); if (tmp == null) { tmp = new Tag { Name = tag.Trim() }; unitOfWork.TagRepository.Insert(tmp); unitOfWork.Save(); } photo.Tags.Add(tmp); } }