public async Task <IActionResult> Index()
        {
            var user      = _userManager.GetUserAsync(User).Result;
            var salariati = _context.Salariat
                            .Include(x => x.Client)
                            .Where(x => x.ClientId == user.ClientId)
                            .OrderBy(x => x.Client.Denumire)
                            .ToList();

            CerereDocument cerere = new CerereDocument();

            if (await _userManager.IsInRoleAsync(user, ConstantVar.Rol_Admin_Firma))
            {
                cerere.ApplicationUserId = user.Id;
                cerere.DenumireClient    = _context.Client.FindAsync(user.ClientId.Value).Result.Denumire;
                ViewData["Salariati"]    = new SelectList(salariati, "SalariatId", "NumePrenume");
            }
            else
            {
                ViewData["Salariati"] = new SelectList(_context.Salariat.ToList(), "SalariatId", "NumePrenume");
            }

            cerere.TipCerere      = _context.TipCereri.ToList();
            ViewData["TipCereri"] = new SelectList(cerere.TipCerere, "TipCerereId", "Denumire");

            return(View(cerere));
        }
        public async Task <IActionResult> Create(CerereDocument data)
        {
            var user  = _userManager.GetUserAsync(User).Result;
            var admin = _context.ApplicationUsers.Where(x => x.Email.Contains("dana_moisi")).FirstOrDefault();

            if (ModelState.IsValid)
            {
                data.DenumireCerere = _context.TipCereri.Find(data.TipCerereId).Denumire;
                var    salariat       = _context.Salariat.FirstOrDefault(x => x.SalariatId == data.SalariatId);
                string redirectToPage = "/Clienti/CereriDocumente/Index";

                if (data.CerereDocumentId != 0)
                {
                    // edit
                    _context.CereriDocumente.Update(data);
                    await _context.SaveChangesAsync();

                    // trimitem notificari adminilor
                    Notificare notificare = new Notificare();
                    notificare.Text = user.Nume + " a editat cererea de " + data.DenumireCerere + " pentru firma " + data.DenumireClient + ", salariatul "
                                      + salariat.NumePrenume + " deadline la " + data.DataStart;
                    notificare.RedirectToPage = redirectToPage;
                    await _notificationManager.CreateAsyncNotificationForAdmin(notificare, admin.Id);

                    return(Json(new { success = true, message = "Cerere editata cu succes!" }));
                }
                else
                {
                    // add
                    _context.CereriDocumente.Add(data);
                    await _context.SaveChangesAsync();

                    // trimitem notificari adminilor
                    Notificare notificare = new Notificare();
                    notificare.Text = user.Nume + " a depus o cerere de " + data.DenumireCerere + " pentru firma " + data.DenumireClient + ", salariatul "
                                      + salariat.NumePrenume + " deadline la " + data.DataStart;
                    notificare.RedirectToPage = redirectToPage;
                    await _notificationManager.CreateAsyncNotificationForAdmin(notificare, admin.Id);

                    return(Json(new { success = true, message = "Cerere adaugata cu succes!" }));
                }
            }
            return(Json(new { success = false, message = "A aparut o eroare, va rugam reincercati!" }));
        }