public ActionResult Create([Bind(Include = "EntryNo,AlbumNo,RecordCompany,ReleaseCode")] Release release)
        {
            if (ModelState.IsValid)
            {
                db.Release.Add(release);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AlbumNo = new SelectList(db.Album, "EntryNo", "Author", release.AlbumNo);
            return(View(release));
        }
        public ActionResult Create([Bind(Include = "UserNo,AlbumNo,ReleaseNo,Comment")] CollectionEntry collectionEntry)
        {
            if (ModelState.IsValid)
            {
                collectionEntry.HashControlValue = Utils.GetStringSha256Hash(collectionEntry.UserNo + collectionEntry.AlbumNo + collectionEntry.ReleaseNo);
                db.CollectionEntry.Add(collectionEntry);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AlbumNo   = new SelectList(db.Album, "EntryNo", "Author", collectionEntry.AlbumNo);
            ViewBag.ReleaseNo = new SelectList(db.Release, "EntryNo", "RecordCompany", collectionEntry.ReleaseNo);
            ViewBag.UserNo    = new SelectList(db.Users, "Id", "Email", collectionEntry.UserNo);
            return(View(collectionEntry));
        }
示例#3
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... */
            }
        }
示例#4
0
        public bool RemoveFavourite(string userName, int productId)
        {
            MyApplicationDbContext ctx = new MyApplicationDbContext();

            ApplicationUser user = applicationUserManager.FindByName(userName);

            ctx.FavouritesList.Remove(ctx.FavouritesList.Where(p => p.UserId == user.Id && p.ProductID == productId).First());

            try
            {
                ctx.SaveChanges();
                return(true);
            }
            catch (DbEntityValidationException exc)
            {
                foreach (var err in exc.EntityValidationErrors)
                {
                    foreach (var errrr in err.ValidationErrors)
                    {
                        string st = errrr.ErrorMessage;
                    }
                }
                return(false);
            }
        }
示例#5
0
        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();
        }
示例#6
0
        public ActionResult Create([Bind(Include = "EntryNo,AlbumNo,ReleaseNo,FilePath,UserUploaded,PostedFile,IsMain")] Photo photo)
        {
            if (ModelState.IsValid)
            {
                if (photo.PostedFile != null && photo.AlbumNo != null)
                {
                    photo.FilePath = Upload(photo.PostedFile, (int)photo.AlbumNo);
                }
                //photo.UserUploaded = User.Identity.Name;
                db.Photos.Add(photo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AlbumNo   = new SelectList(db.Album, "EntryNo", "MetaDescription", photo.AlbumNo);
            ViewBag.ReleaseNo = new SelectList(db.Release, "EntryNo", "MetaDescription", photo.ReleaseNo);
            //ViewBag.UserUploaded = User.Identity.Name;
            return(View(photo));
        }
示例#7
0
        //public ActionResult Create([Bind(Include = "EntryNo,Author,Title,Duration")] Album album)
        //public ActionResult Create([Bind(Include = "Author,Title,Duration,YearOfProduction", Prefix ="Duration")] Album album)
        public ActionResult Create(Album album, string CoverArtHidden)
        {
            //bind include (albo exclude) definiuje kolumny, jakie można ustawić daną funkcją.
            //dzięki temu zaboiega sie próbom atakowania np. przez fidller, gdzię można przypisać wartości do propertisów,
            //którym nie chcemy na to pozwolic
            if (ModelState.IsValid)
            {
                db.Album.Add(album);
                db.SaveChanges();

                if (!String.IsNullOrEmpty(CoverArtHidden))
                {
                    Photo photo = new Photo();
                    photo.AlbumNo      = album.EntryNo;
                    photo.IsMain       = true;
                    photo.UserUploaded = HttpContext.User.Identity.Name;

                    //zapis obrazka na dysku do pliku
                    if (!Directory.Exists(MusicCollector.Properties.Resources.PHOTO_PATH + "/" + album.EntryNo))
                    {
                        Directory.CreateDirectory(MusicCollector.Properties.Resources.PHOTO_PATH + "/" + album.EntryNo);
                    }
                    string fileName = DateTime.Now.Subtract(DateTime.MinValue.AddYears(1969)).TotalMilliseconds + ".jpg";
                    string filePath = Path.Combine(MusicCollector.Properties.Resources.PHOTO_PATH + "/" + album.EntryNo, fileName);
                    filePath = filePath.Replace(@"\", "/");

                    var bytes = Convert.FromBase64String(CoverArtHidden);
                    using (var imageFile = new FileStream(filePath, FileMode.Create))
                    {
                        imageFile.Write(bytes, 0, bytes.Length);
                        imageFile.Flush();
                    }

                    photo.FilePath = album.EntryNo + "/" + fileName;
                    db.Photos.Add(photo);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            return(View(album));
        }
示例#8
0
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();
            new ToDoListDefaultDataCreator(_context).Create();

            _context.SaveChanges();
        }
        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();
        }
示例#10
0
        public ActionResult Delete(int?id)
        {
            var page = db.SaDPages.Where(p => p.SaDPageId == id).FirstOrDefault();

            if (page != null && page.SaDPageActive == false)
            {
                db.SaDPages.Remove(page);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("NotFound", "Error"));
        }
示例#11
0
        public AdministrationServiceResult addOrUpdateLaboratory(LaboratoryInputModel inputData)
        {
            AdministrationServiceResult result = new AdministrationServiceResult();

            if (inputData != null)
            {
                var city = context.Municipios.Where(c => c.Id == inputData.CityId).FirstOrDefault();
                if (city == null)
                {
                    result.Errors.Add("Municipio no válido");
                }

                var state = context.Estados.Where(st => st.Id == inputData.StateId).FirstOrDefault();
                if (state == null)
                {
                    result.Errors.Add("Estado no válido");
                }

                if (result.IsValid)
                {
                    AdministrationServiceResult operationResult = null;
                    if (inputData.Id > 0)
                    {
                        operationResult = this.updateLaboratory(inputData, city, state);
                    }
                    else
                    {
                        operationResult = this.createLaboratory(inputData, city, state);
                    }
                    context.SaveChanges();
                    result.Errors.AddRange(operationResult.Errors);
                }
            }
            else
            {
                result.Errors.Add("Datos de entrada no válidos");
            }

            return(result);
        }
示例#12
0
        private void CreateToDoLists()
        {
            // Admin role for host

            var hasAnyToDo = _context.ToDoLists.FirstOrDefault() != null;

            if (!hasAnyToDo)
            {
                _context.ToDoLists.Add(new ToDo.ToDoList {
                    TaskName = "Utility Bill", Desciption = "Pay Utility Bill", IsCompleted = true, Category = "category 1", UserId = 1
                });
                _context.ToDoLists.Add(new ToDo.ToDoList {
                    TaskName = "Membership", Desciption = "Clear Membership due", IsCompleted = false, Category = "category 1", UserId = 1
                });
                _context.ToDoLists.Add(new ToDo.ToDoList {
                    TaskName = "Utility Bill 1", Desciption = "Pay Utility Bill", IsCompleted = false, Category = "category 1", UserId = 1
                });
                _context.ToDoLists.Add(new ToDo.ToDoList {
                    TaskName = "Utility Bill 2", Desciption = "Pay Utility Bill", IsCompleted = false, Category = "category 1", UserId = 1
                });
                _context.ToDoLists.Add(new ToDo.ToDoList {
                    TaskName = "Utility Bill 3", Desciption = "Pay Utility Bill", IsCompleted = false, Category = "category 1", UserId = 1
                });
                _context.ToDoLists.Add(new ToDo.ToDoList {
                    TaskName = "Utility Bill 4", Desciption = "Pay Utility Bill", IsCompleted = false, Category = "category 1", UserId = 1
                });
                _context.ToDoLists.Add(new ToDo.ToDoList {
                    TaskName = "Utility Bill 5", Desciption = "Pay Utility Bill", IsCompleted = false, Category = "category 1", UserId = 1
                });
                _context.ToDoLists.Add(new ToDo.ToDoList {
                    TaskName = "Utility Bill 6", Desciption = "Pay Utility Bill", IsCompleted = false, Category = "category 1", UserId = 1
                });
                _context.SaveChanges();
            }

            // Grant all permissions to admin role for host


            _context.SaveChanges();
        }
示例#13
0
        public AdministrationServiceResult PreviewPage(DoctorsOfficeInputModel inputModel)
        {
            AdministrationServiceResult result;

            var referencePage = this.getPage(inputModel.page.Id);

            if (referencePage != null)
            {
                result = CreatePageFromReference(inputModel, referencePage);
                if (result.IsValid == true)
                {
                    WhoWeArePage page = result.ResultObject as WhoWeArePage;
                    result.ResultObject = page;

                    IFormatter   formatter = new BinaryFormatter();
                    MemoryStream stream    = new MemoryStream();
                    formatter.Serialize(stream, page);
                    stream.Close();

                    var storedPagePreview = context.PagePreviews.Find("DoctorsOffice");
                    if (storedPagePreview != null)
                    {
                        context.PagePreviews.Remove(storedPagePreview);
                    }

                    context.PagePreviews.Add(new PagePreview {
                        PageName = "DoctorsOffice", PageValue = stream.GetBuffer()
                    });
                    context.SaveChanges();
                }
            }
            else
            {
                result = new AdministrationServiceResult();
                result.Errors.Add("Pagina no válida");
            }
            return(result);
        }
        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();
            }
        }
        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 MyApplicationAuthorizationProvider())
                              .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();
            }
        }
示例#16
0
        private void buttonLoadCitiesInformation_Click(object sender, EventArgs e)
        {
            string fileName = "K:/csv.csv";
            MyApplicationDbContext context = new MyApplicationDbContext();
            //List<String> messages = new List<string>();
            Dictionary <String, Estados>    states = new Dictionary <string, Estados>();
            Dictionary <String, Municipios> cities = new Dictionary <string, Municipios>();


            StreamReader fileReader = new StreamReader(fileName, Encoding.UTF8);

            while (!fileReader.EndOfStream)
            {
                string line = fileReader.ReadLine();

                string[] lineComponents = this.getLineComponents(line);
                string   ceco           = lineComponents[0];
                string   branchName     = lineComponents[1].Trim();
                string   stateName      = lineComponents[2].Trim();
                string   cityName       = lineComponents[3].Trim();
                string   latitude       = lineComponents[4].Trim();
                string   longitude      = lineComponents[5].Trim();

                Estados state = null;

                if (!states.ContainsKey(stateName))
                {
                    state = new Estados()
                    {
                        Name = stateName
                    };
                    context.Estados.Add(state);
                    context.SaveChanges();
                    states[stateName] = state;
                }
                else
                {
                    state = states[stateName];
                }

                Municipios city = null;
                if (!cities.ContainsKey(cityName))
                {
                    city = new Municipios()
                    {
                        Name = cityName
                    };
                    var cs = new EstadosMunicipios()
                    {
                        Estado    = state,
                        Municipio = city
                    };
                    context.Municipios.Add(city);
                    context.EstadosMunicipios.Add(cs);
                    context.SaveChanges();
                    cities[cityName] = city;
                }
                else
                {
                    city = cities[cityName];
                }

                Branch b = new Branch()
                {
                    BranchName            = branchName,
                    BranchLatitude        = latitude,
                    BranchLongitude       = longitude,
                    BranchCeco            = ceco,
                    BranchActive          = true,
                    BranchConsult         = true,
                    BranchTwentyFourHours = true,
                    BranchFose            = true,
                    City  = city,
                    State = state
                };
                context.Branchs.Add(b);
                context.SaveChanges();
            }

            //listBox1.DataSource = messages;

            fileReader.Close();
        }
 public IActionResult Create(Question question)
 {
     _db.Questions.Add(question);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#18
0
        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 MyApplicationAuthorizationProvider())
                              .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();
            }
        }