public async Task <IActionResult> Create([Bind("ProblemaModelID,DataIntroducere,UtilajModelID,ProblemaDescriere,ComentariuMentenanta,LastPersonUpdateRow")] ProblemaModel problemaModel) { if (ModelState.IsValid) { problemaModel.ComentariuMentenanta = "-"; problemaModel.Stare = Status.Nerezolvat; _context.Add(problemaModel); await _context.SaveChangesAsync(); // Send Mail string filePathMailModel = Path.Combine(_env.WebRootPath, "Fisiere\\MailDate.JSON"); MailModel mailModel = _emailSender.GetMailModelAsync(filePathMailModel).Result; UtilajModel utilajName = _context.UtilajModels.FirstOrDefault(utilaj => utilaj.UtilajModelID == problemaModel.UtilajModelID); await _emailSender.SendEmailAsync(mailModel.FromAdress, mailModel.ToAddress, mailModel.Subjsect, problemaModel.LastPersonUpdateRow + mailModel.Messaege + problemaModel.ProblemaDescriere + $" la utilajul: {utilajName.Utilaj}"); return(RedirectToAction(nameof(Index))); } ViewData["ResponsabilModelID"] = new SelectList(_context.ResponsabilModel, "ResponsabilModelID", "Email", problemaModel.ResponsabilModelID); ViewData["UtilajModelID"] = new SelectList(_context.UtilajModels, "UtilajModelID", "Utilaj", problemaModel.UtilajModelID); return(View(problemaModel)); }
public async Task <IActionResult> Edit(int id, [Bind("ProblemaModelID,DataIntroducere,UtilajModelID,ProblemaDescriere,ComentariuMentenanta,Stare,ResponsabilModelID,TermenFinalizare,LastPersonUpdateRow")] ProblemaModel problemaModel) { if (id != problemaModel.ProblemaModelID) { return(NotFound()); } if (ModelState.IsValid) { try { // Daca completeaza user Mentenanta se pune automat in lucru if (User.IsInRole("Mentenanta") && problemaModel.Stare != Status.Rezolvat) { problemaModel.Stare = Status.InLucru; } // Se actualizeaza date server _context.Update(problemaModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProblemaModelExists(problemaModel.ProblemaModelID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ResponsabilModelID"] = new SelectList(_context.ResponsabilModel, "ResponsabilModelID", "Email", problemaModel.ResponsabilModelID); ViewData["UtilajModelID"] = new SelectList(_context.UtilajModels, "UtilajModelID", "Utilaj", problemaModel.UtilajModelID); return(View(problemaModel)); }