예제 #1
0
        public IActionResult NewActivity(ActivityViewModel activity)
        {
            int UserId = (int)HttpContext.Session.GetInt32("user_id");

            DateTime DatetoCheck = DateTime.Now;

            // if (activity.Date < DatetoCheck)
            // {
            //     this.ModelState.AddModelError("Date", "Date has to be in the future");
            // }

            if (ModelState.IsValid)
            {
                Activity newActivity = new Activity
                {
                    Title        = activity.Title,
                    Time         = activity.Time,
                    Date         = activity.Date,
                    Duration     = activity.Duration,
                    DurationType = activity.DurationType,
                    CreatedAt    = DateTime.Now,
                    UpdatedAt    = DateTime.Now,
                    UserId       = UserId,
                    Description  = activity.Description
                };
                _context.Activities.Add(newActivity);
                _context.SaveChanges();
                return(RedirectToAction("activity", new { id = newActivity.ActivityId }));
            }
            else
            {
                ViewBag.ActivityErrors = ModelState.Values;
                return(View("newactivitypage"));
            }
        }
예제 #2
0
        public async Task SeedAsync()
        {
            _context.Database.EnsureCreated();

            try
            {
                if (!_context.Users.Any())
                {
                    User admin = new User()
                    {
                        UserName       = "******",
                        Email          = "*****@*****.**",
                        EmailConfirmed = true,
                        SignedBefore   = true
                    };
                    #region Add Doctor
                    //User doctor = new User()
                    //{
                    //    UserName = "******",
                    //    Email = "*****@*****.**",
                    //    EmailConfirmed = true,
                    //    SignedBefore = true
                    //};
                    //Employee doctorEmployee = new Employee()
                    //{

                    //}


                    #endregion

                    await _roleManager.CreateAsync(new IdentityRole("ClinicCenterAdmin"));

                    await _roleManager.CreateAsync(new IdentityRole("ClinicAdmin"));

                    await _roleManager.CreateAsync(new IdentityRole("Doctor"));

                    await _roleManager.CreateAsync(new IdentityRole("Nurse"));

                    await _roleManager.CreateAsync(new IdentityRole("Patient"));

                    var result = await _userManager.CreateAsync(admin, "Gaja1234!");

                    var result1 = await _userManager.AddToRoleAsync(admin, "ClinicCenterAdmin");

                    if (result != IdentityResult.Success)
                    {
                        throw new InvalidOperationException("Could not create new user in seeder");
                    }
                    admin.UserId = Guid.Parse(admin.Id);

                    _context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception message: {0}", ex.Message);
            }
        }
예제 #3
0
        public async Task <bool> Update(E entity)
        {
            lock ( _lock)
            {
                try
                {
                    _centerContext.SaveChanges();

                    return(true);
                }
                catch (Exception e)
                {
                    return(false);

                    throw e;
                }
            }
        }
예제 #4
0
 public IActionResult Register(RegisterViewModel validation)
 {
     if (ModelState.IsValid)
     {
         User newUser = new User
         {
             FirstName = validation.FirstName,
             LastName  = validation.LastName,
             Email     = validation.Email,
             Password  = validation.Password,
             CreatedAt = DateTime.Now,
             UpdatedAt = DateTime.Now
         };
         _context.Users.Add(newUser);
         _context.SaveChanges();
         HttpContext.Session.SetInt32("user_id", newUser.UserId);
         return(RedirectToAction("Home", "Action"));
     }
     else
     {
         ViewBag.Errors = ModelState.Values;
         return(View("index"));
     }
 }