Exemplo n.º 1
0
        public Exam SaveExam(Exam exam)
        {
            var dbExam = _context.Exam.Where(x => x.Id == exam.Id).FirstOrDefault();

            if (dbExam == null)
            {
                _context.Exam.Add(exam);
                _context.SaveChanges();

                return(exam);
            }
            else
            {
                dbExam.Datetime      = exam.Datetime;
                dbExam.ExamType      = exam.ExamType;
                dbExam.Anameza       = exam.Anameza;
                dbExam.Zakljucak     = exam.Zakljucak;
                dbExam.LocationId    = exam.LocationId;
                dbExam.PacijentId    = exam.PacijentId;
                dbExam.DoctorId      = exam.DoctorId;
                dbExam.Price         = exam.Price;
                dbExam.DiscountPrice = exam.DiscountPrice;
                dbExam.Taken         = exam.Taken;
                //dbExam.Active = exam.Active;

                _context.SaveChanges();

                return(dbExam);
            }
        }
Exemplo n.º 2
0
        public UserDto Register(UserDto user)
        {
            if (user.Ime.Length <= 3)
            {
                return(null);
            }

            if (user.Prezime.Length <= 3)
            {
                return(null);
            }

            if (user.Username.Length <= 3)
            {
                return(null);
            }

            if (user.Password.Length <= 3)
            {
                return(null);
            }

            var userBase = _context.User.Where(x => x.Username == user.Username).FirstOrDefault();


            if (userBase != null)
            {
                return(null);
            }
            Guid g = Guid.NewGuid();


            var newUser = new User
            {
                Aktivan          = 0,
                Prezime          = user.Prezime,
                Ime              = user.Ime,
                Username         = user.Username,
                Password         = user.Password,
                Email            = user.Email,
                Adresa           = user.Adresa,
                Grad             = user.Grad,
                Drzava           = user.Drzava,
                Lbo              = "123",
                Telefon          = user.Telefon,
                AktivacioniToken = Convert.ToBase64String(g.ToByteArray())
                                   .Substring(0, 22)
                                   .Replace("/", "_")
                                   .Replace("+", "-")
            };

            _context.User.Add(newUser);

            _context.SaveChanges();

            newUser.UserRole = new List <UserRole>();
            newUser.UserRole.Add(new UserRole {
                UserId = newUser.Id, RoleId = 3
            });
            _context.SaveChanges();

            _emailSender.SendEmailAsync(newUser.Email, "Registration confirmation", "http://localhost:51447/api/user/activate?code=" + newUser.AktivacioniToken);



            var newUserDto = new UserDto
            {
                Aktivan  = 1,
                Prezime  = newUser.Prezime,
                Ime      = newUser.Ime,
                Username = newUser.Username,
                Password = newUser.Password,
                Id       = newUser.Id,
            };


            return(newUserDto);
        }