コード例 #1
0
        public async Task <ActionResult <Zaposlen> > PostZaposlen(Zaposlen zaposlen)
        {
            _context.Zaposleni.Add(zaposlen);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetZaposlen", new { id = zaposlen.ID }, zaposlen));
        }
コード例 #2
0
        public async Task <IActionResult> PutZaposlen([FromRoute] int id, [FromBody] Zaposlen zaposlen)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != zaposlen.SifraZaposlenogID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #3
0
        public async Task <IActionResult> PutZaposlen(int id, Zaposlen zaposlen)
        {
            if (id != zaposlen.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #4
0
 private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 {
     using (ITransaction tx = m_Session.BeginTransaction())
     {
         Zaposlen new_user = (Zaposlen)(e.Row.DataBoundItem);
         m_Session.Delete(new_user);
         tx.Commit();
     }
 }
コード例 #5
0
        public IHttpActionResult Post(Zaposlen zaposlen)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _repository.Add(zaposlen);
            return(CreatedAtRoute("DefaultApi", new { id = zaposlen.Id }, zaposlen));
        }
コード例 #6
0
        public async Task <IActionResult> PostZaposlen([FromBody] Zaposlen zaposlen)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Zaposleni.Add(zaposlen);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetZaposlen", new { id = zaposlen.SifraZaposlenogID }, zaposlen));
        }
コード例 #7
0
        public void Update(Zaposlen zaposlen)
        {
            db.Entry(zaposlen).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
コード例 #8
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Ime,Priimek,Naslov,Telefon,DatumRojstva,DatumZaposlitve,Spol,Kadrovanje")] Zaposlen zaposlen)
        {
            if (id != zaposlen.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                { IdentityRole role;
                  if (zaposlen.Kadrovanje)
                  {
                      role = await _context.Roles.FirstOrDefaultAsync(m => m.Name == "Manager");
                  }
                  else
                  {
                      role = await _context.Roles.FirstOrDefaultAsync(m => m.Name == "Worker");
                  }
                  var user = await _context.Users.FirstOrDefaultAsync(m => m.Zaposlen.ID == id);

                  var userRole = await _context.UserRoles.FirstOrDefaultAsync(m => m.UserId == user.Id);

                  if (userRole != null)
                  {
                      _context.UserRoles.Remove(userRole);
                  }
                  var userRoleNew = new IdentityUserRole <string> {
                      UserId = user.Id, RoleId = role.Id
                  };
                  _context.UserRoles.Add(userRoleNew);


                  _context.Update(zaposlen);
                  await _context.SaveChangesAsync(); }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ZaposlenExists(zaposlen.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(zaposlen));
        }
コード例 #9
0
 private void initUser()
 {
     try
     {
         ITransaction tx  = m_Session.BeginTransaction();
         Zaposlen     usr = new Zaposlen();
         usr.UporabniskoIme = "test";
         usr.Geslo          = "test";
         m_Session.Save(usr);
         tx.Commit();
     }
     catch (Exception ex)
     {
         ResetSession();
     }
 }
コード例 #10
0
        public IActionResult Post([FromBody] Zaposlen zaposlen)
        {
            broker.OtvoriKonekciju();
            try
            {
                var command = new NpgsqlCommand($"INSERT INTO \"zaposleni_view1\"(\"sifraZaposlenog\", ime, prezime, jmbg, \"brLicneKarte\")" +
                                                $"VALUES({zaposlen.sifraZaposlenog}, '{zaposlen.ime}', '{zaposlen.prezime}', '{zaposlen.jmbg}', '{zaposlen.brLicneKarte}');", broker.connection);
                command.ExecuteNonQuery();
            }
            catch (NpgsqlException ex)
            {
                return(Ok(ex.Message));
            }
            broker.ZatvoriKonekciju();

            return(Ok(zaposlen));
        }
コード例 #11
0
 public IHttpActionResult PutId(int id, Zaposlen zaposlen)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (id != zaposlen.Id)
     {
         return(BadRequest());
     }
     try
     {
         _repository.Update(zaposlen);
     }
     catch
     {
         return(BadRequest());
     }
     return(Ok(zaposlen));
 }
コード例 #12
0
        //preverjanje ujemanja gesla z uporabnikom
        private bool CheckUser(string user, string pass)
        {
            bool result = false;

            try
            {
                ITransaction tx    = m_Session.BeginTransaction();
                IQuery       query = m_Session.CreateQuery("from Zaposlen d where d.UporabniskoIme = ?");
                Zaposlen     res   = query.SetString(0, user).UniqueResult <Zaposlen>();
                tx.Commit();
                if (res != null && res.Geslo.Equals(pass))
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                ResetSession();
            }
            return(result);
        }
コード例 #13
0
 void bs_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
 {
     switch (e.ListChangedType)
     {
     case ListChangedType.ItemChanged:
     {
         using (ITransaction tx = m_Session.BeginTransaction())
         {
             Zaposlen new_user = (Zaposlen)(_bs.List[e.NewIndex]);
             if (new_user.UporabniskoIme == null)
             {
                 new_user.UporabniskoIme = "";
             }
             if (new_user.Geslo == null)
             {
                 new_user.Geslo = "";
             }
             m_Session.Save(new_user);
             tx.Commit();
         }
         break;
     }
     }
 }
コード例 #14
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var zapView = new ZaposlenViewModel {
                    Ime = Input.Ime, Priimek = Input.Priimek, Naslov = Input.Naslov, Telefon = Input.Telefon, DatumRojstva = Input.DatumRojstva, Spol = Input.Spol, Slika = Input.Slika
                };
                string uniqueFileName = UploadedFile(zapView);
                var    zapTmp         = new Zaposlen {
                    Ime = Input.Ime, Priimek = Input.Priimek, Naslov = Input.Naslov, Telefon = Input.Telefon, DatumRojstva = Input.DatumRojstva, Spol = Input.Spol, PhotoPath = uniqueFileName, Kadrovanje = Input.Kadrovska
                };
                var user = new Uporabniki {
                    UserName = Input.Email, Email = Input.Email, Zaposlen = zapTmp
                };

                var result = await _userManager.CreateAsync(user, Input.Password);

                if (Input.Kadrovska)
                {
                    var roleResult = await _userManager.AddToRoleAsync(user, "Manager");
                }
                else
                {
                    var roleResult = await _userManager.AddToRoleAsync(user, "Worker");
                }
                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
コード例 #15
0
 public void Delete(Zaposlen zaposlen)
 {
     db.zaposleni.Remove(zaposlen);
     db.SaveChanges();
 }
コード例 #16
0
ファイル: DbInitializer.cs プロジェクト: klemen-1337/e-kader
        public static void Initialize(EkadriContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Zaposleni.Any())
            {
                return;   // DB has been seeded
            }

            var adminRole = new IdentityRole {
                Name = "Admin", NormalizedName = "ADMIN"
            };

            context.Roles.Add(adminRole);

            var managerRole = new IdentityRole {
                Name = "Manager", NormalizedName = "MANAGER"
            };

            context.Roles.Add(managerRole);

            var workerRole = new IdentityRole {
                Name = "Worker", NormalizedName = "WORKER"
            };

            context.Roles.Add(workerRole);

            context.SaveChanges();

            var zaposleni = new Zaposlen[]
            {
                new Zaposlen {
                    Ime = "Miha", Priimek = "Žnidar", Naslov = "Tvoja mt planina", Telefon = 420420420, DatumRojstva = DateTime.Parse("2019-09-01"), Spol = "Ž"
                },
                new Zaposlen {
                    Ime = "Klemen", Priimek = "Štefe", Naslov = "Tvoja mt planina", Telefon = 420420420, DatumRojstva = DateTime.Parse("2019-09-01"), Spol = "Ž"
                },
                new Zaposlen {
                    Ime = "Marjan", Priimek = "Kovač", Naslov = "Tvoja mt planina", Telefon = 420420420, DatumRojstva = DateTime.Parse("2019-09-01"), Spol = "Ž"
                },
                new Zaposlen {
                    Ime = "Janez", Priimek = "Pegam", Naslov = "Tvoja mt planina", Telefon = 420420420, DatumRojstva = DateTime.Parse("2019-09-01"), Spol = "Ž"
                },
                new Zaposlen {
                    Ime = "Florjan", Priimek = "Gasilec", Naslov = "Tvoja mt planina", Telefon = 420420420, DatumRojstva = DateTime.Parse("2019-09-01"), Spol = "Ž"
                },
                new Zaposlen {
                    Ime = "Cene", Priimek = "Novak", Naslov = "Tvoja mt planina", Telefon = 420420420, DatumRojstva = DateTime.Parse("2019-09-01"), Spol = "Ž"
                },
                new Zaposlen {
                    Ime = "Mirjan", Priimek = "Salam", Naslov = "Tvoja mt planina", Telefon = 420420420, DatumRojstva = DateTime.Parse("2019-09-01"), Spol = "Ž"
                },
            };

            foreach (Zaposlen zaposlen in zaposleni)
            {
                context.Zaposleni.Add(zaposlen);
            }
            context.SaveChanges();

            var delovnaMesta = new DelovnaMesta[] {
                new DelovnaMesta {
                    DelovnaMestaID = 420, Oddelek = "IT", Lokacija = "Kranj", NazivDelovnegaMesta = "Programer"
                },
                new DelovnaMesta {
                    DelovnaMestaID = 123, Oddelek = "Proizvodnja", Lokacija = "Ljubljana", NazivDelovnegaMesta = "Upravljalec stroja"
                },
                new DelovnaMesta {
                    DelovnaMestaID = 690, Oddelek = "Proizvodnja", Lokacija = "Kranj", NazivDelovnegaMesta = "Čistilka"
                },
                new DelovnaMesta {
                    DelovnaMestaID = 231, Oddelek = "Komerciala", Lokacija = "Kranj", NazivDelovnegaMesta = "Komercialist"
                },
                new DelovnaMesta {
                    DelovnaMestaID = 222, Oddelek = "Komerciala", Lokacija = "Kranj", NazivDelovnegaMesta = "Šef"
                },
                new DelovnaMesta {
                    DelovnaMestaID = 666, Oddelek = "IT", Lokacija = "Ljubljana", NazivDelovnegaMesta = "Programer"
                },
            };

            foreach (DelovnaMesta mesto in delovnaMesta)
            {
                context.DelovnaMesta.Add(mesto);
            }

            context.SaveChanges();

            var zaposlitve = new Zaposlitve[] {
                new Zaposlitve {
                    ZaposlenID = 1, DelovnaMestaID = 420, DatumZaposlitve = DateTime.Parse("2019-09-01")
                },
                new Zaposlitve {
                    ZaposlenID = 2, DelovnaMestaID = 123, DatumZaposlitve = DateTime.Parse("2019-09-01")
                },
                new Zaposlitve {
                    ZaposlenID = 3, DelovnaMestaID = 420, DatumZaposlitve = DateTime.Parse("2019-09-01")
                },
                new Zaposlitve {
                    ZaposlenID = 4, DelovnaMestaID = 231, DatumZaposlitve = DateTime.Parse("2019-09-01")
                },
                new Zaposlitve {
                    ZaposlenID = 5, DelovnaMestaID = 666, DatumZaposlitve = DateTime.Parse("2019-09-01")
                },
                new Zaposlitve {
                    ZaposlenID = 6, DelovnaMestaID = 222, DatumZaposlitve = DateTime.Parse("2019-09-01")
                },
                new Zaposlitve {
                    ZaposlenID = 7, DelovnaMestaID = 420, DatumZaposlitve = DateTime.Parse("2019-09-01")
                },
            };

            foreach (Zaposlitve zap in zaposlitve)
            {
                context.Zaposlitve.Add(zap);
            }
            context.SaveChanges();


            var hasher = new PasswordHasher <Uporabniki>();

            Zaposlen zapAdmin = new Zaposlen {
                Ime = "admin", Priimek = "admin", Naslov = "Cesta pod goro 69", Telefon = 420420420, DatumRojstva = DateTime.Parse("2019-09-01"), Spol = "Ž", Kadrovanje = true
            };
            String pass = hasher.HashPassword(null, "Admin123!");

            context.Zaposleni.Add(zapAdmin);
            Uporabniki upoAdmin = new Uporabniki {
                UserName = "******", NormalizedUserName = "******", NormalizedEmail = "*****@*****.**", Email = "*****@*****.**", PasswordHash = pass, Zaposlen = zapAdmin
            };

            context.Users.Add(upoAdmin);

            Zaposlen zapWorker = new Zaposlen {
                Ime = "Jaka", Priimek = "Novak", Naslov = "Tvoja mt planina", Telefon = 420420420, DatumRojstva = DateTime.Parse("2019-09-01"), Spol = "Ž", Kadrovanje = false
            };
            String pass2 = hasher.HashPassword(null, "Admin123!");

            context.Zaposleni.Add(zapWorker);
            Uporabniki upoWorker = new Uporabniki {
                UserName = "******", NormalizedUserName = "******", NormalizedEmail = "*****@*****.**", Email = "*****@*****.**", PasswordHash = pass2, Zaposlen = zapWorker
            };

            context.Users.Add(upoWorker);

            var roleAdmin = new IdentityUserRole <string> {
                UserId = upoAdmin.Id, RoleId = adminRole.Id
            };
            var roleWorker = new IdentityUserRole <string> {
                UserId = upoWorker.Id, RoleId = workerRole.Id
            };

            context.UserRoles.Add(roleAdmin);
            context.UserRoles.Add(roleWorker);

            context.SaveChanges();
        }
コード例 #17
0
 public void Add(Zaposlen zaposlen)
 {
     db.zaposleni.Add(zaposlen);
     db.SaveChanges();
 }