protected void AddImages_Click(object sender, EventArgs e) { showImage_Click(new object(), new EventArgs()); if (lastImgBytes == null || lastImgBytes.Length == 0) { return; } using (MuseumContext context = new MuseumContext()) { var imgs = context.Images; var img = new Model.Image(); img.FrameNumber = -1; img.Name = namePic.Text == ""? "Нет названия":namePic.Text; img.Description = descriptionPic.Text == ""? "Описание отсутствует":descriptionPic.Text; img.Picture = lastImgBytes; imgs.Add(img); context.SaveChanges(); } lastImgBytes = default; lastImg = null; }
public void LoadData() { string name = "asd"; using (MuseumContext db = new MuseumContext()) { db.Pictures.Load(); name = db.Pictures.First().Name; } PictureModel[] models = new PictureModel[3]; models[0] = new PictureModel() { Author = name, Name = "Mishki" }; models[1] = new PictureModel() { Author = "Van-Gogh", Name = "The Starry Night" }; models[2] = new PictureModel() { Author = "Da-Vinci", Name = "Mona-Lisa" }; var jsonData = JsonConvert.SerializeObject(models); var stopWriteToken = new CancellationToken(false); Response.WriteAsync(jsonData, stopWriteToken); }
private static string GetInfoTextByTypeId(int typeId) { var _db = new MuseumContext(); var info = _db.Informations.FirstOrDefault(i => i.InformationTypeId == typeId); return(info != null ? info.Text : ""); }
private string GetAdmData() { string json; using (var context = new MuseumContext()) { json = JsonConvert.SerializeObject(context.Admins.ToList()); } return(json); }
public async Task <IActionResult> GetUser([FromQuery] UserDtoParameters parameters) { if (!JudgeRoles(1)) { return(Json(new { code = -1, msg = "您没有权限进行此操作!" })); } MuseumContext _context = new MuseumContext(); IManageUser _manageUser = new ManageUser(_context); var users = await _manageUser.GetUsersAsync(parameters); return(Ok(new { code = 0, data = new{ items = users, total = users.TotalCount } })); }
private static string GetImages() { string json; using (MuseumContext context = new MuseumContext()) { var images = context.Images.ToList(); json = JsonConvert.SerializeObject(images); var obj = JsonConvert.DeserializeObject <List <Model.Image> >(json); } return(json); }
public IActionResult Login([FromBody] Admin admin) { MuseumContext _context = new MuseumContext(); IManageAdmin _manage = new ManageAdmin(_context); if (_manage.GetAdminByUsername(admin.Username) == null) { return(Json(new { code = -1, msg = "用户名不存在" })); } if (_manage.CheckPassword(admin.Username, admin.Password)) { admin = _manage.GetAdminByUsername(admin.Username); AdminSystem.AddLog(admin.Username, "登录"); return(Json(new { code = 0, data = new { token = GetToken(admin) }, msg = "登录成功" })); } return(Json(new { code = -1, msg = "用户名或密码错误" })); }
private string DeleteImg(string picId) { try { var id = Int32.Parse(picId); using (var context = new MuseumContext()) { var imgToDelete = context.Images.Where(x => x.Id == id).FirstOrDefault(); context.Images.Remove(imgToDelete); context.SaveChanges(); } } catch (Exception ex) { return(ex.Message); } return("success"); }
private string SetPicData(string picId, string picNumber) { try { var id = Int32.Parse(picId); var newNumber = Int32.Parse(picNumber); using (var context = new MuseumContext()) { var pic = context.Images.Where(img => img.Id == id).FirstOrDefault(); pic.FrameNumber = newNumber; context.SaveChanges(); } } catch (Exception ex) { return(ex.ToString()); } return("success"); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.IsAuthenticated() || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Добавление нового пользователя в базу данных using (MuseumContext db = new MuseumContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Проверка наличия пользователя в базе данных if (user == null) { // Добавление имени в таблицу профиля db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "Имя пользователя уже существует. Введите другое имя пользователя."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public SimpleMembershipInitializer() { Database.SetInitializer <MuseumContext>(null); try { using (var context = new MuseumContext()) { if (!context.Database.Exists()) { // Создание базы данных SimpleMembership без схемы миграции Entity Framework ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("AzureConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("Не удалось инициализировать базу данных ASP.NET Simple Membership. Чтобы получить дополнительные сведения, перейдите по адресу: http://go.microsoft.com/fwlink/?LinkId=256588", ex); } }
protected void Button1_Click(object sender, EventArgs e) { string adminName = ""; using (var context = new MuseumContext()) { var admins = context.Admins.ToList(); var enteredAdmin = admins.Where(x => x.Login == login.Text && x.Password == password.Text).FirstOrDefault(); if (enteredAdmin != null) { adminName = enteredAdmin.Name; } } if (adminName != "") { Label3.Text = $"Добро пожаловать, {adminName}!"; login.Enabled = false; password.Enabled = false; fileUpload.Visible = true; AddImages.Visible = true; namePic.Visible = true; descriptionPic.Visible = true; Label4.Visible = true; Label5.Visible = true; showImage.Visible = true; Label1.Text = ""; lastImg = null; lastImgBytes = null; } else { Label1.Text = "Неверный логин или пароль!"; } }
public ArtworkRepository(MuseumContext context) : base(context) { }
public ManageComment(MuseumContext appDbContext) { _context = appDbContext; }
public VisitorRepository(MuseumContext context) : base(context) { }
public ManageAdmin(MuseumContext museumContext) { _context = museumContext; }
public RepositoryBase(MuseumContext context) { this.context = context; }
public AccountRepository(MuseumContext context) : base(context) { }
public RoomRepository(MuseumContext context) : base(context) { }
public UnitOfWork(string connectionString) { this.db = new MuseumContext(connectionString); this.connectionString = connectionString; }
public Repository(MuseumContext db) { this.db = db; table = db.Set <T>(); }
public Repository(string connectionString) { this.db = new MuseumContext(connectionString); table = db.Set <T>(); }