public ActionResult Create([Bind(Include = "Image_Link,Title,Description,Congrats_Messages")] Kudo kudo) { try { if (ModelState.IsValid) { Wish newwish = new Wish(); newwish.KudoID = kudo.KudoID; newwish.Message = kudo.Congrats_Messages[0].Message; db.Kudos.Add(kudo); db.Wishes.Add(newwish); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException /*dex*/) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(kudo)); }
public void CreateKudo(Kudo kudo, User sender) { kudo.DateCreated = DateTime.UtcNow; kudo.DateUpdated = DateTime.UtcNow; kudo.Sender = sender; kudoRepository.Add(kudo); }
public IActionResult Edit(KudoFormViewModel kudoForm) { if (ModelState.IsValid) { Kudo kudo = kudoMapper.MapKudoFormViewModelToModel(kudoForm); if (kudoForm.KudoViewModel.Id.HasValue) { kudoService.ChangeKudo(kudo); } else { User sender = userService.GetUser(this.User); kudoService.CreateKudo(kudo, sender); } kudoService.SaveChanges(); return(RedirectToAction("Index")); } else { kudoMapper.FillKudoFormViewModel(kudoForm); return(View(kudoForm)); } }
public ViewResult Details(int id) { Kudo kudo = kudoService.GetKudo(id); User sender = userService.GetUser(this.User); ViewBag.SenderId = sender.Id; return(View(kudo)); }
public ActionResult DeleteConfirmed(int id) { Kudo kudo = db.Kudos.Find(id); db.Kudos.Remove(kudo); db.SaveChanges(); return(RedirectToAction("Index")); }
public void UpdateText(Kudo kudo) { var kudoDbo = this.context.Kudos.First(k => k.Id == kudo.Id); kudoDbo.Text = kudo.Text; kudoDbo.UpdatedAt = DateTime.Now; this.context.Kudos.Update(kudoDbo); this.context.SaveChanges(); }
public int Update(Kudo kudo, CancellationToken cancelationToken = default(CancellationToken)) { kudo.UpdatedAt = DateTime.Now; var id = this.context.Kudos.Update(kudo).Entity.Id; this.context.SaveChanges(); return(id); }
public async Task <int> CreateAsync(Kudo kudo, CancellationToken cancelationToken) { kudo.CreateAt = DateTime.Now; var entry = await this.context.Kudos.AddAsync(kudo).ConfigureAwait(false); this.context.SaveChanges(); return(entry.Entity.Id); }
public ActionResult Edit([Bind(Include = "KudosId,Comment,Photo,NGOUserId,ItemPostId")] Kudo kudo) { if (ModelState.IsValid) { db.Entry(kudo).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ItemPostId = new SelectList(db.ItemPosts, "ItemPostId", "ItemName", kudo.ItemPostId); ViewBag.NGOUserId = new SelectList(db.Users, "UserId", "FirstName", kudo.NGOUserId); return(View(kudo)); }
public KudoFormViewModel MapKudoModelToFormViewModel(Kudo kudo) { IEnumerable <KudoCategory> categories = kudoCategoyService.GetCategories(); IEnumerable <User> users = userService.GetUsers(); var kudoFormViewModel = new KudoFormViewModel(categories, users); kudoFormViewModel.KudoViewModel = MapKudoModelToViewModel(kudo); kudoFormViewModel.KudoViewModel.Sender = kudo.Sender; return(kudoFormViewModel); }
/// <summary> /// Gets the kudo command message by removing the first n words from the message. /// </summary> /// <param name="kudo">The kudo object</param> /// <param name="n">The number of word to remove from left to right</param> /// <returns></returns> public static string GetKudoMessage(this Kudo kudo, int n) { var commandText = kudo.CommandText; var textList = commandText.Split(' ').ToList(); textList.RemoveRange(0, n); var delimiter = " "; return(textList.Aggregate((i, j) => i + delimiter + j)); }
public KudoViewModel MapKudoModelToViewModel(Kudo kudo) { var kudoViewModel = new KudoViewModel(); kudoViewModel.Id = kudo.Id; kudoViewModel.CategoryId = kudo.Category.Id; kudoViewModel.Content = kudo.Content; kudoViewModel.Sender = kudo.Sender; kudoViewModel.ReceiverId = kudo.Receiver.Id; kudoViewModel.DateUpdated = kudo.DateUpdated; return(kudoViewModel); }
public async Task <IActionResult> CreateKudoAsync(Kudo Kudo) { try { await _kudoService.CreateKudoAsync(Kudo); return(Ok()); } catch (BussinessException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Internal server error: {ex.Message}")); } }
public IActionResult Edit(int id) { Kudo kudo = kudoService.GetKudo(id); User sender = userService.GetUser(this.User); if (kudo.Sender.Id != sender.Id) { return(this.RedirectToAction("AccessDenied", "Account")); } KudoFormViewModel kudoForm = kudoMapper.MapKudoModelToFormViewModel(kudo); return(View("Edit", kudoForm)); }
// GET: Kudo/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Kudo kudo = db.Kudos.Find(id); if (kudo == null) { return(HttpNotFound()); } return(View(kudo)); }
// GET: /Kudos/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Kudo kudo = db.Kudos.Find(id); if (kudo == null) { return(HttpNotFound()); } ViewBag.ItemPostId = new SelectList(db.ItemPosts, "ItemPostId", "ItemName", kudo.ItemPostId); ViewBag.NGOUserId = new SelectList(db.Users, "UserId", "FirstName", kudo.NGOUserId); return(View(kudo)); }
public Kudo MapKudoFormViewModelToModel(KudoFormViewModel kudoForm) { Kudo kudo; if (kudoForm.KudoViewModel.Id.HasValue) { kudo = kudoService.GetKudo(kudoForm.KudoViewModel.Id.Value); } else { kudo = new Kudo(); } kudo.Category = kudoCategoyService.GetCategory(kudoForm.KudoViewModel.CategoryId.Value); kudo.Receiver = userService.GetUser(kudoForm.KudoViewModel.ReceiverId); kudo.Content = kudoForm.KudoViewModel.Content; return(kudo); }
public ActionResult Create([Bind(Include = "KudosId,Comment,Photo,NGOUserId,ItemPostId")] Kudo kudo) { if (ModelState.IsValid) { if (Session["imageData"] != null) { kudo.Photo = Session["imageData"] as byte[]; } db.Kudos.Add(kudo); db.SaveChanges(); Session["imageData"] = null; Session["imageFileName"] = null; return(RedirectToAction("Index")); } Session["imageData"] = null; Session["imageFileName"] = null; ViewBag.ItemPostId = new SelectList(db.ItemPosts, "ItemPostId", "ItemName", kudo.ItemPostId); ViewBag.NGOUserId = new SelectList(db.Users, "UserId", "FirstName", kudo.NGOUserId); return(View(kudo)); }
/// <summary> /// add kudos from emails /// </summary> /// <param name="emails"></param> /// <returns></returns> public async Task InsertKudoFromEmails(List <EmailMessage> emails) { var kudos = new List <Kudo>(); foreach (var email in emails) { var senders = await _employeeRepository.GetEmployeeByEmails(email.FromAddresses.Select(i => i.Address.ToString()).ToList()); if (senders.Count() > 0) { var senderInfo = senders.Single(); var receivers = await _employeeRepository.GetEmployeeByEmails(email.ToAddresses.Select(i => i.Address.ToString()).ToList()); if (receivers.Count() > 0) { foreach (var receiver in receivers) { var kudo = new Kudo { SenderId = senderInfo.Id, ReceiverId = receiver.Id, KudoDetail = new KudoDetail { Content = email.Content, //default kudo type KudoTypeId = 1 } }; kudos.Add(kudo); } } } } if (kudos.Count > 0) { await _kudoRepository.InsertKudos(kudos); } }
/// <summary> /// create kudo with username /// </summary> /// <param name="kudo"></param> /// <returns></returns> public async Task CreateKudoByUserNameAsync(KudoDto kudo) { var sender = _employeeRepository.GetEmployeeByUserName(kudo.SenderUsername); var reciver = _employeeRepository.GetEmployeeByUserName(kudo.ReceiverUsername); if (sender != null && reciver != null) { var newKudo = new Kudo { SenderId = sender.Id, ReceiverId = reciver.Id, KudoDetail = new KudoDetail { Content = kudo.Content, SlackEmoji = kudo.SlackEmoji, KudoTypeId = kudo.KudoTypeId } }; await _kudoRepository.InsertAsync(newKudo); } }
internal static ISlackResponseMessage BuildKudoReplacedResponse(Kudo kudo) { throw new NotImplementedException(); }
public void ChangeKudo(Kudo kudo) { kudo.DateUpdated = DateTime.UtcNow; kudoRepository.Update(kudo); }
/// <summary> /// Delete an existing kudo /// </summary> /// <returns></returns> public async Task DeleteKudoAsync(Kudo kudo) { await _kudoRepository.DeleteAsync(kudo); }
/// <summary> /// Update an existing kudo /// </summary> /// <returns></returns> public async Task UpdateKudoAsync(Kudo kudo) { await _kudoRepository.UpdateAsync(kudo); }
/// <summary> /// Create a new kudo type /// </summary> /// <returns></returns> public async Task CreateKudoAsync(Kudo kudo) { await _kudoRepository.InsertAsync(kudo); }
public async Task GiveListoidAKudo(Kudo kudo) { _context.Kudos.Add(kudo); await _context.SaveChangesAsync(); }
public async Task <int> CreateAsync(Kudo kudo) { return(await this.CreateAsync(kudo, default(CancellationToken)).ConfigureAwait(false)); }
public int Update(Kudo kudo) { return(this.Update(kudo, default(CancellationToken))); }