Example #1
0
        public void Execute(NapraviKorisnika request)
        {
            if (request == null)
            {
                throw new NullReferenceException("Korisnik");
            }
            if (Context.Korisnici.Any(k => k.Email == request.Email))
            {
                throw new EntityAlreadyExists("Korisnik");
            }

            var korisnik = new Korisnik
            {
                Ime         = request.Ime,
                Prezime     = request.Prezime,
                Email       = request.Email,
                Password    = HashPasswordCommand.MD5Hash(request.Password),
                DateCreated = DateTime.Now
            };

            try
            {
                Context.Korisnici.Add(korisnik);
                Context.SaveChanges();
            }
            catch (Exception)
            {
                throw new EntryPointNotFoundException();
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.Clear();
            Console.WriteLine("Choose an option:");
            Console.WriteLine("1) Migrate with DbUp");
            Console.WriteLine("2) Seed dummy data");
            Console.WriteLine("3) Hash password");
            Console.WriteLine("q) Exit");
            Console.Write("\r\nSelect an option: ");

            String option = Console.ReadLine();

            switch (option)
            {
            case "1":
                MigrateDBUPCommand.RunCommand();
                break;

            case "2":
                DummyRecipesCommand.RunCommand();
                break;

            case "3":
                HashPasswordCommand.RunCommand();
                break;

            case "q":
                Environment.Exit(0);
                break;

            default:
                Console.WriteLine("Invalid option");
                break;
            }

            Console.WriteLine("\nApp will now close. If you want to run more commands then restart.");
            Console.ReadLine();
        }
Example #3
0
        public void Execute(NapraviKorisnika request)
        {
            var korisnik = Context.Korisnici.Find(request.KorisnikId);

            if (Context.Korisnici.Where(x => x.Id != request.KorisnikId).Any(k => k.Email == request.Email))
            {
                throw new EntityAlreadyExists("Korisnik");
            }

            try
            {
                korisnik.DateModified = DateTime.Now;
                korisnik.Ime          = request.Ime;
                korisnik.Prezime      = request.Prezime;
                korisnik.Email        = request.Email;
                korisnik.Password     = HashPasswordCommand.MD5Hash(request.Password);
                Context.SaveChanges();
            }
            catch
            {
                throw new NullReferenceException("Something went wrong with update in db");
            }
        }