private string[] GetTegsEdit(TShitsViewModel model) { string tag = model.Tag.Replace(" ", " "); string[] tags = tag.Split(' '); return(tags); }
private void AddDbImage(TShitsViewModel model) { _db.images.Add(new Image { image = model.image }); _db.SaveChanges(); }
public async Task <IActionResult> Edit(TShitsViewModel model, string returnUrl) { ChangingParametersShirt(model, await GetUser()); if (!String.IsNullOrEmpty(model.Tag)) { AddTagsEdit(model); } return(Redirect(returnUrl)); }
private string name(TShitsViewModel model) { if (model.TShirtName != "" && !String.IsNullOrEmpty(model.TShirtName)) { return(model.TShirtName); } else { return("There should have been text"); } }
private string description(TShitsViewModel model) { if (model.description != "" && !String.IsNullOrEmpty(model.description)) { return(model.description); } else { return("There should have been text"); } }
private void ChangingParametersShirt(TShitsViewModel model, User user) { var result = _db.tshirts.FirstOrDefault(item => item.id == model.id); var topics = _db.topics.FirstOrDefault(item => item.nameTopic == model.Topic); result.name = model.TShirtName; result.description = model.description; result.themeId = topics.id; result.createDate = DateTime.Now.ToString("MM/dd/yyyy"); result.Sex = model.sex; _db.tshirts.Update(result); _db.SaveChanges(); }
private void AddShirt(TShitsViewModel model, Topic topics, User user, string description, string name) { _db.tshirts.Add(new Shirt { image = model.image, name = name, description = description, userId = user.Id, themeId = topics.id, createDate = DateTime.Now.ToString("MM/dd/yyyy"), Sex = model.sex });; _db.SaveChanges(); }
private void AddTag(string[] tags, TShitsViewModel model) { for (int i = 0; i < tags.Length; i++) { if (_db.tags.FirstOrDefault(item => item.name == tags[i]) == null) { _db.tags.Add(new Tag { name = tags[i] }); _db.SaveChanges(); } Shirt shirt = _db.tshirts.FirstOrDefault(item => item.name == model.TShirtName); Tag tag1 = _db.tags.FirstOrDefault(item => item.name == tags[i]); _db.tagInTShirts.Add(new TagInTShirt { shirtid = shirt.id, tagid = tag1.id }); _db.SaveChanges(); } }
public async Task <IActionResult> SetRating(TShitsViewModel model, string returnUrl) { User user = await _userManager.GetUserAsync(User); Shirt shirt = _db.tshirts.FirstOrDefault(item => item.id == model.id); Rating mark = _db.ratings.FirstOrDefault(item => item.shirt == shirt && item.user == user); for (int i = 4; i >= 0; i--) { if (model.ratings[i] == true) { if (mark == null) { _db.ratings.Add(new Rating { shirt = shirt, user = user, value = i }); await _db.SaveChangesAsync(); return(Redirect(returnUrl)); } else { mark.value = i; _db.ratings.Update(mark); await _db.SaveChangesAsync(); return(Redirect(returnUrl)); } } } if (mark != null) { _db.ratings.Remove(mark); await _db.SaveChangesAsync(); } return(Redirect(returnUrl)); }
public async Task <IActionResult> Constructor(TShitsViewModel model, string userId, string returnUrl) { var topics = GetTopicConstructor(model); User user = await _userManager.FindByIdAsync(userId); _db.tshirts.Add(new Shirt { image = model.image, name = name(model), description = description(model), userId = user.Id, themeId = topics.id, createDate = DateTime.Now.ToString("MM/dd/yyyy"), Sex = model.sex });; //} await _db.SaveChangesAsync(); if (!String.IsNullOrEmpty(model.Tag)) { AddTag(GetTegsConstructor(model), model); } return(Redirect(returnUrl)); }
public async Task <IActionResult> EditShirt(TShitsViewModel model) { await _db.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); }
private Topic GetTopicConstructor(TShitsViewModel model) { return(_db.topics.FirstOrDefault(item => item.nameTopic == model.Topic)); }
public IActionResult AddImage(TShitsViewModel model) { AddDbImage(model); return(RedirectToAction("Index", "Home")); }