Ejemplo n.º 1
0
        public async Task <IActionResult> PutAlarmy(int id, Alarmy alarmy)
        {
            if (id != alarmy.Id)
            {
                return(BadRequest());
            }

            _context.Entry(alarmy).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AlarmyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Title,Employer,ReleaseDate,About,Level,Level2,UseId")] Alarmy alarmy)
        {
            switch (alarmy.Level)
            {
            case 1:
                alarmy.Level2 = "Niski";
                break;

            case 2:
                alarmy.Level2 = "Średni";
                break;

            case 3:
                if (User.IsInRole("Emp3"))
                {
                    alarmy.Level2 = "Wysoki";
                }
                else
                {
                    return(RedirectToAction(nameof(No)));
                }
                break;
            }
            string Userid = User.Identity.Name;

            alarmy.UseId = Userid;
            if (ModelState.IsValid)
            {
                _context.Add(alarmy);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(alarmy));
        }