Example #1
0
        public IActionResult Add(ViewModel assign)
        {
            Assignment assignment = assign.Assignment;

            if (assign.SelectedTags != null)
            {
                int id = assign.SelectedTags.ElementAt(0);

                for (int i = 0; i < assign.SelectedTags.Count(); i++)
                {
                    AssignmentTag assignmentTag = new AssignmentTag {
                        Assignment   = assignment,
                        AssignmentId = assign.Assignment.Id,
                        Tag          = _context.Tags.Single(n => n.Id == assign.SelectedTags.ElementAt(i)),
                        TagId        = assign.SelectedTags.ElementAt(i)
                    };
                    _context.AssignmentTags.Add(assignmentTag);
                }
            }

            _context.Add(assignment);
            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #2
0
 public async Task <IActionResult> Create(AssignmentItem model)
 {
     if (ModelState.IsValid)
     {
         _db.Add(model);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
        public ActionResult Create([Bind(Include = "Id,Name,Address")] Manufacturer manufacturer)
        {
            if (ModelState.IsValid)
            {
                db.Manufacturers.Add(manufacturer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(manufacturer));
        }
Example #4
0
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

            if (defaultEdition == null)
            {
                defaultEdition = new Edition {
                    Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName
                };
                _context.Editions.Add(defaultEdition);
                _context.SaveChanges();

                /* Add desired features to the standard edition, if wanted... */
            }
        }
Example #5
0
        public static void MockCustomer(AssignmentDbContext assignmentDbContext)
        {
            var customer1 = new Customer()
            {
                Name       = "Customer1",
                Email      = "*****@*****.**",
                Phone      = 71234568,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now
            };

            var customer2 = new Customer()
            {
                Name       = "Customer2",
                Email      = "*****@*****.**",
                Phone      = 234567189,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now
            };

            var customer3 = new Customer()
            {
                Name       = "Customer3",
                Email      = "*****@*****.**",
                Phone      = 1239874,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now
            };

            assignmentDbContext.Add(customer1);
            assignmentDbContext.Add(customer2);
            assignmentDbContext.Add(customer3);
            assignmentDbContext.SaveChanges();
        }
Example #6
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
Example #7
0
        public ActionResult Create(FormCollection formCollection)
        {
            var name     = formCollection.Get("Name");
            var quantity = int.Parse(formCollection.Get("Quantity"));
            var price    = float.Parse(formCollection.Get("Price"));
            var year     = int.Parse(formCollection.Get("Year"));

            var newProduct = new Product
            {
                Name     = name,
                Quantity = quantity,
                Price    = price,
                Year     = year
            };

            dbContext.Products.Add(newProduct);
            dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);
            _context.SaveChanges();
        }
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();
            new DefaultCowsSensorsCreator(_context).Create();

            _context.SaveChanges();
        }
        private void CreateCows()
        {
            var    cows = _context.Cows.Count();
            Random rnd  = new Random();

            var farms  = new string[] { "A", "B", "C" };
            var states = new string[] { "Open", "Inseminated", "Pregnant", "Dry" };

            if (cows <= 0)
            {
                for (int i = 0; i < 100; i++)
                {
                    _context.Cows.Add(new Cows.Cow
                    {
                        FarmId = farms[rnd.Next(farms.Length)],
                        State  = states[rnd.Next(states.Length)]
                    });
                }
                _context.SaveChanges();
            }
        }
 public ActionResult Create(MarkupPlan model)
 {
     if (string.IsNullOrWhiteSpace(model.Name))
     {
         ModelState.AddModelError("", "Name Required");
         return(View(model));
     }
     try
     {
         _context.MarkupPlan.Add(model);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", e.Message);
         return(View(model));
     }
 }
        private void CreateDefaultTenant()
        {
            // Default tenant

            var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == AbpTenantBase.DefaultTenantName);

            if (defaultTenant == null)
            {
                defaultTenant = new Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName);

                var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);
                if (defaultEdition != null)
                {
                    defaultTenant.EditionId = defaultEdition.Id;
                }

                _context.Tenants.Add(defaultTenant);
                _context.SaveChanges();
            }
        }
Example #13
0
        private void CreateHostRoleAndUsers()
        {
            // Admin role for host

            var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);

            if (adminRoleForHost == null)
            {
                adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin)
                {
                    IsStatic = true, IsDefault = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role for host

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == null && p.RoleId == adminRoleForHost.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new AssignmentAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = null,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRoleForHost.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user for host

            var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName);

            if (adminUserForHost == null)
            {
                var user = new User
                {
                    TenantId         = null,
                    UserName         = AbpUserBase.AdminUserName,
                    Name             = "admin",
                    Surname          = "admin",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    IsActive         = true
                };

                user.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(user, "123qwe");
                user.SetNormalizedNames();

                adminUserForHost = _context.Users.Add(user).Entity;
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));
                _context.SaveChanges();

                _context.SaveChanges();
            }
        }
        private void CreateRolesAndUsers()
        {
            // Admin role

            var adminRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin);

            if (adminRole == null)
            {
                adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin)
                {
                    IsStatic = true
                }).Entity;
                _context.SaveChanges();
            }

            // Grant all permissions to admin role

            var grantedPermissions = _context.Permissions.IgnoreQueryFilters()
                                     .OfType <RolePermissionSetting>()
                                     .Where(p => p.TenantId == _tenantId && p.RoleId == adminRole.Id)
                                     .Select(p => p.Name)
                                     .ToList();

            var permissions = PermissionFinder
                              .GetAllPermissions(new AssignmentAuthorizationProvider())
                              .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant) &&
                                     !grantedPermissions.Contains(p.Name))
                              .ToList();

            if (permissions.Any())
            {
                _context.Permissions.AddRange(
                    permissions.Select(permission => new RolePermissionSetting
                {
                    TenantId  = _tenantId,
                    Name      = permission.Name,
                    IsGranted = true,
                    RoleId    = adminRole.Id
                })
                    );
                _context.SaveChanges();
            }

            // Admin user

            var adminUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == AbpUserBase.AdminUserName);

            if (adminUser == null)
            {
                adminUser                  = User.CreateTenantAdminUser(_tenantId, "*****@*****.**");
                adminUser.Password         = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(adminUser, "123qwe");
                adminUser.IsEmailConfirmed = true;
                adminUser.IsActive         = true;

                _context.Users.Add(adminUser);
                _context.SaveChanges();

                // Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id));
                _context.SaveChanges();
            }
        }
        public static void MockTransaction(AssignmentDbContext assignmentDbContext)
        {
            var customer = assignmentDbContext.Customers.Select(c => c);

            var transaction1OfCustomer1 = new Transaction()
            {
                Currency   = "USD",
                Amount     = (decimal)39.75,
                Status     = StatusTransaction.Success,
                CustomerId = customer.First().Id,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now,
                Date       = DateTime.Now
            };

            var transaction2OfCustomer1 = new Transaction()
            {
                Currency   = "EUR",
                Amount     = (decimal)40.17,
                Status     = StatusTransaction.Canceled,
                CustomerId = customer.First().Id,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now,
                Date       = DateTime.Now
            };

            var transaction3OfCustomer1 = new Transaction()
            {
                Currency   = "THB",
                Amount     = (decimal)150.15,
                Status     = StatusTransaction.Failed,
                CustomerId = customer.First().Id,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now,
                Date       = DateTime.Now
            };

            var transaction1OfCustomer2 = new Transaction()
            {
                Currency   = "JYP",
                Amount     = (decimal)60,
                Status     = StatusTransaction.Success,
                CustomerId = customer.Last().Id,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now,
                Date       = DateTime.Now
            };

            var transaction2OfCustomer2 = new Transaction()
            {
                Currency   = "GBP",
                Amount     = (decimal)48.95,
                Status     = StatusTransaction.Canceled,
                CustomerId = customer.Last().Id,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now,
                Date       = DateTime.Now
            };

            var transaction3OfCustomer2 = new Transaction()
            {
                Currency   = "CNY",
                Amount     = (decimal)7985.07,
                Status     = StatusTransaction.Failed,
                CustomerId = customer.Last().Id,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now,
                Date       = DateTime.Now
            };

            assignmentDbContext.Add(transaction1OfCustomer1);
            assignmentDbContext.Add(transaction2OfCustomer1);
            assignmentDbContext.Add(transaction3OfCustomer1);
            assignmentDbContext.Add(transaction1OfCustomer2);
            assignmentDbContext.Add(transaction2OfCustomer2);
            assignmentDbContext.Add(transaction3OfCustomer2);

            assignmentDbContext.SaveChanges();
        }