public MusicCafeController(ILogger <MusicCafeController> logger, MyDatabaseContext context)
        {
            _context = context;
            _logger  = logger;

            System.Diagnostics.Debug.WriteLine("heres the context " + _context);
        }
Exemple #2
0
 public IEnumerable <Message> AllMessages()
 {
     using (var context = new MyDatabaseContext())
     {
         return(context.Messages.Where((item) => item.Timesent != null).OrderByDescending(item => item.Timesent).ToList());
     }
 }
Exemple #3
0
        public ActionResult LoginEmpresa(Empresa empresaModel)
        {
            MyDatabaseContext db = new MyDatabaseContext();

            if (empresaModel != null)
            {
                var vEmpresa = db.Empresa.Where(p => p.Email.Equals(empresaModel.Email)).FirstOrDefault();

                if (vEmpresa != null)
                {
                    if (CriptografiaSenha.Compara(empresaModel.Senha, vEmpresa.Senha))
                    {
                        Session["EmpresaLogada"] = vEmpresa;
                        return(View("MainPage"));
                    }
                    else
                    {
                        TempData["Mensagem"] = "Usuario ou senha errada!";
                        return(View("LoginEmpresa", vEmpresa));
                    }
                }
                else
                {
                    TempData["Mensagem"] = "Não há nenhuma conta registrada nesse email";
                    return(View("LoginEmpresa", empresaModel));
                }
            }

            return(View());
        }
 public List <Student> ListAllStudents()
 {
     using (var context = new MyDatabaseContext())
     {
         return(context.Students.ToList());
     }
 }
        public bool Create(Employee emp)
        {
            var context = new MyDatabaseContext();

            context.Employees.Add(emp);
            return(context.SaveChanges() > 0);
        }
Exemple #6
0
        public AddWindow(int id = 0)
        {
            ID = id;

            InitializeComponent();

            var model = new ViewModels.AddWindowModel(this);

            AcceptButton.Command = model.AcceptCommand;
            RejectButton.Command = model.RejectCommand;

            if (ID != 0)
            {
                // nawiązanie połączenia z bazą danych
                using var db = new MyDatabaseContext();

                // wyszukanie przy pomocy LINQ osoby o podanym ID
                // oraz utworzenie odpowiedniego obiektu (klasy Person)
                var person = (from p in db.Persons
                              join c in db.Contacts
                              on p.ID equals c.PersonID
                              where p.ID == ID
                              select new Person {
                    ID = p.ID,
                    FirstName = p.FirstName,
                    LastName = p.LastName,
                    Age = p.Age,
                    Contact = new Contact {
                        City = c.City,
                        Street = c.Street,
                        HomeNumber = c.HomeNumber,
                        PostCode = c.PostCode,
                        PostOffice = c.PostOffice,
                        Email = c.Email,
                        Phone = c.Phone
                    }
                }).First();

                //// wyświetlanie pobrancyh danych w odpowiednich kontrolkach

                // ustawienie nowego tytułu okna
                this.Caption.Text = $"Aktualizacja użytkownika: {person.FirstName} {person.LastName}";
                this.Title        = this.Caption.Text;

                // adekwatny tekst na przycisku (zamiast zapisz zmiana na Zaaktualizuj)
                this.AcceptButton.Content = "Zaaktualizuj";

                // wprowadzenie danych do odpowiednich pól edytowalnych
                this.Firstname.Text  = person.FirstName;
                this.Surname.Text    = person.LastName;
                this.Age.Text        = Convert.ToString(person.Age);
                this.City.Text       = person.Contact.City;
                this.Street.Text     = person.Contact.Street;
                this.HomeNumer.Text  = person.Contact.HomeNumber;
                this.PostCode.Text   = person.Contact.PostCode;
                this.PostOffice.Text = person.Contact.PostOffice;
                this.Email.Text      = person.Contact.Email;
                this.Phone.Text      = person.Contact.Phone;
            }
        }
Exemple #7
0
        public virtual System.Web.Mvc.ActionResult Edit
            ([System.Web.Mvc.Bind(Include = "Id,RoleId,IsActive,Age,Username,Password,FullName,Description")] Models.User user)
        {
            if (ModelState.IsValid)
            {
                MyDatabaseContext.Entry(user).State = EntityState.Modified;

                MyDatabaseContext.SaveChanges();

                return(RedirectToAction(MVC.Users.Index()));
            }

            // **************************************************
            var varRoles =
                MyDatabaseContext.Roles
                .Where(current => current.IsActive)
                .OrderBy(current => current.Name)
                .ToList()
            ;

            ViewBag.RoleId =
                new System.Web.Mvc.SelectList
                    (items: varRoles, dataValueField: "Id", dataTextField: "Name", selectedValue: user.RoleId);
            // **************************************************

            return(View(model: user));
        }
        private void FillDepartmentsDropdownList()
        {
            var db          = new MyDatabaseContext();
            var departments = db.Departments.ToList();

            ViewBag.DepartmentList = new SelectList(departments, "DepartmentId", "DepartmentName");
        }
        public virtual System.Web.Mvc.ActionResult Create([System.Web.Mvc.Bind(Include = "IsActive,Name")] Models.Role role)
        {
            // **************************************************
            // Business Validation

            if ((role.Name != null) && (role.Name.Length < 4) && (role.IsActive))
            {
                //ModelState.AddModelError
                //	(key: "Name", errorMessage: "Some business error message!");

                ModelState.AddModelError
                    (key: string.Empty, errorMessage: "Some business error message!");
            }
            // **************************************************

            if (ModelState.IsValid)
            {
                MyDatabaseContext.Roles.Add(role);

                MyDatabaseContext.SaveChanges();

                return(RedirectToAction(MVC.Roles.Index()));
            }

            //return (View());
            return(View(model: role));
        }
Exemple #10
0
        public virtual System.Web.Mvc.ActionResult Edit(Models.Contents Content)
        {
            Models.Contents originalItem =
                MyDatabaseContext.Contents.Find(Content.Id);

            if (originalItem == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                originalItem.Annotatedtext = Content.Annotatedtext;
                originalItem.ImageUrl      = Content.ImageUrl;
                originalItem.IsActive      = Content.IsActive;
                originalItem.ReviewTime    = System.DateTime.Now;
                originalItem.Text          = Content.Text;
                originalItem.Title         = Content.Title;

                MyDatabaseContext.SaveChanges();

                return(RedirectToAction(MVC.Users.Products.Index()));
            }

            return(View(model: Content));
        }
        /// <summary>
        /// 新增黑名单进程
        /// </summary>
        /// <param name="newBLProgress"></param>
        /// <returns></returns>
        public async Task <bool> AddBlackListProgressAsync(MyDatabaseContext.BlackListProgress newBLProgress)
        {
            using (var db = new MyDatabaseContext())
            {
                MyDatabaseContext.BlackListProgress Announcement;

                if (newBLProgress.Type == 2)
                {
                    Announcement = await db.BlackListProgresses.SingleOrDefaultAsync(m => m.Uwp_ID.Equals(newBLProgress.ID));
                }
                else
                {
                    Announcement = await db.BlackListProgresses.SingleOrDefaultAsync(m => m.FileName == newBLProgress.FileName && m.Type == newBLProgress.Type);
                }
                if (Announcement == null)
                {
                    db.BlackListProgresses.Add(newBLProgress);
                    await db.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    await new DialogService().ShowAsync("程序已存在!");
                    return(false);
                }
            }
        }
Exemple #12
0
        public virtual System.Web.Mvc.ActionResult Edit
            ([System.Web.Mvc.Bind(Include = "Id,IsActive,Name")] Models.Role role)
        {
            Models.Role oOriginalRole =
                MyDatabaseContext.Roles
                .Find(role.Id);

            if (oOriginalRole == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                //MyDatabaseContext.Entry(role).State = EntityState.Modified;

                oOriginalRole.Name     = role.Name;
                oOriginalRole.IsActive = role.IsActive;

                MyDatabaseContext.SaveChanges();

                return(RedirectToAction(MVC.Roles.Index()));
            }

            return(View(model: role));
        }
        public ActionResult Details(int id)
        {
            var context  = new MyDatabaseContext();
            var employee = context.Employees.Single(x => x.EmployeeId == id);

            return(View(employee));
        }
        public virtual System.Web.Mvc.ActionResult Create(Models.Traffic traffic)
        {
            if (traffic.EndTime < traffic.StartTime)
            {
                string errorMessage =
                    "EndTime Cannot be Smaller Than StartTime";

                ModelState.AddModelError(key: string.Empty, errorMessage: errorMessage);
            }

            if (ModelState.IsValid)
            {
                MyDatabaseContext.Traffics.Add(traffic);
                MyDatabaseContext.SaveChanges();
                return(RedirectToAction(MVC.Traffics.Index()));
            }
            /******************************************************************************************/
            var users =
                MyDatabaseContext.Users
                .Where(current => current.IsActive)
                .OrderBy(current => current.Username)
                .ToList()
            ;

            ViewBag.UserId =
                new System.Web.Mvc.SelectList(items: users, dataValueField: nameof(Models.User.Id), dataTextField: nameof(Models.User.Username),
                                              selectedValue: traffic.UserId);
            /******************************************************************************************/
            return(View(model: traffic));
        }
        static Unit()
        {
            _context = new MyDatabaseContext("MyConnStr");

            Products   = new RepositoryBase <Product>(_context);
            Categories = new RepositoryBase <Category>(_context);
        }
Exemple #16
0
        public virtual System.Web.Mvc.ActionResult Edit(Models.Matters Matter)
        {
            Models.Matters originalItem =
                MyDatabaseContext.Matter.Find(Matter.Id);

            if (originalItem == null)
            {
                return(HttpNotFound());
            }

            var foundedItem =
                MyDatabaseContext.Matter
                .Where(current => current.Id != Matter.Id)
                .Where(current => string.Compare(current.Name, Matter.Name, true) == 0)
                .FirstOrDefault();

            if (foundedItem != null)
            {
                ModelState.AddModelError
                    (key: "Name", errorMessage: "Name is exist! Please choose another one...");
            }

            if (ModelState.IsValid)
            {
                originalItem.Name     = Matter.Name;
                originalItem.CodePath = Matter.CodePath;

                MyDatabaseContext.SaveChanges();

                return(RedirectToAction(MVC.Admin.Matters.Index()));
            }

            return(View(model: Matter));
        }
Exemple #17
0
        /// <summary>
        /// 更改某个id相同的Task的信息
        /// </summary>
        /// <param name="updateTask"></param>
        /// <returns></returns>
        public async Task <bool> UpdateTaskAsync(MyDatabaseContext.Task updateTask)
        {
            using (var db = new MyDatabaseContext())
            {
                var task = await db.Tasks.SingleOrDefaultAsync(m => m.ID == updateTask.ID);

                if (task != null)
                {
                    task.Date         = updateTask.Date;
                    task.Begin        = updateTask.Begin;
                    task.DefaultTime  = updateTask.DefaultTime;
                    task.FinishTime   = updateTask.FinishTime;
                    task.FinishFlag   = updateTask.FinishFlag;
                    task.UserID       = updateTask.UserID;
                    task.Introduction = updateTask.Introduction;

                    await db.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #18
0
 /// <summary>
 /// 列出所有。
 /// </summary>
 /// <returns></returns>
 public async Task <List <User> > ListUserAsync()
 {
     using (var db = new MyDatabaseContext())
     {
         return(await db.Users.ToListAsync());
     }
 }
Exemple #19
0
        public virtual System.Web.Mvc.ActionResult Edit(Models.Products product)
        {
            Models.Products originalItem =
                MyDatabaseContext.Product.Find(product.Id);

            if (originalItem == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                originalItem.ImageUrl     = product.ImageUrl;
                originalItem.IsActive     = product.IsActive;
                originalItem.IsShow       = product.IsShow;
                originalItem.Prise        = product.Prise;
                originalItem.ProductsId   = product.ProductsId;
                originalItem.ProductsName = product.ProductsName;

                MyDatabaseContext.SaveChanges();

                return(RedirectToAction(MVC.Users.Products.Index()));
            }

            return(View(model: product));
        }
Exemple #20
0
        public async Task <bool> UpdateTaskAsync(String userName, int date, String begin, String end, int defaultTime, int finish, int totalTime, String introduction)
        {
            using (var db = new MyDatabaseContext())
            {
                var currentUser = await db.Users.FirstOrDefaultAsync(m => m.UserName == userName);

                if (currentUser != null)
                {
                    var task = await db.Tasks.SingleOrDefaultAsync(m => m.Date == date && m.Begin == begin && m.UserId == currentUser.Id);

                    if (task != null)
                    {
                        task.DefaultTime  = defaultTime;
                        task.End          = end;
                        task.Finish       = finish;
                        task.Introduction = introduction;
                        task.TotalTime    = totalTime;

                        await db.SaveChangesAsync();

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
        public virtual System.Web.Mvc.ActionResult SetPasswrod(Models.Users user, string Password, string ConfirmPassword)
        {
            if (ConfirmPassword == string.Empty | ConfirmPassword == null)
            {
                ModelState.AddModelError
                    (key: "confirmPassword", errorMessage: "Confirm Password Is Required ..!");
            }

            Models.Users originalItem =
                MyDatabaseContext.User.Find(user.Id);

            if (originalItem == null)
            {
                return(HttpNotFound());
            }

            if (Password != ConfirmPassword)
            {
                ModelState.AddModelError
                    (key: "confirmPassword", errorMessage: "Confirm Password Is Not Correct");
            }

            originalItem.Password = Password;

            MyDatabaseContext.SaveChanges();

            return(RedirectToAction(MVC.Admin.Users.Index()));
        }
Exemple #22
0
 public async Task <List <Progress> > ListProgressAsync()
 {
     using (var db = new MyDatabaseContext())
     {
         return(await db.Progresses.ToListAsync());
     }
 }
Exemple #23
0
        public async Task TestUpdateWithPolicyScopeAsync()
        {
            // Arrange
            MyDatabaseContext       myDatabaseContext   = new MyDatabaseContext();
            Mock <IDatabaseUpdater> databaseManipulator = new Mock <IDatabaseUpdater>();

            databaseManipulator
            .Setup(d => d.UpdateAsync(myDatabaseContext))
            .Returns(Task.FromResult(42));

            PolicyScopeMock policyScopeMock = PolicyScopeMock
                                              .AsyncPolicy(PolicyNames.Primary)
                                              .WithServices(myDatabaseContext, databaseManipulator.Object)
                                              .WithResultType <int>()
                                              .Build();

            WithPolicyScope logic = new WithPolicyScope(policyScopeMock.Object);

            // Act
            int result = await logic.UpdateWithPolicyScopeAsync();

            // Assert
            policyScopeMock.VerifyRunOnce();
            Assert.Equal(42, result);
        }
Exemple #24
0
        public async Task <bool> DeleteTaskAsync(String userName, int date, String begin)
        {
            using (var db = new MyDatabaseContext())
            {
                var currentUser = await db.Users.FirstOrDefaultAsync(m => m.UserName == userName);

                if (currentUser != null)
                {
                    var task = await db.Tasks.SingleOrDefaultAsync(m => m.Date == date && m.Begin == begin && m.UserId == currentUser.Id);

                    if (task != null)
                    {
                        db.Tasks.Remove(task);
                        await db.SaveChangesAsync();

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #25
0
        public string UploadMsg()
        {
            string json = new StreamReader(Request.Body).ReadToEnd();

            try
            {
                using (var context = new MyDatabaseContext())
                {
                    var msg = Newtonsoft.Json.JsonConvert.DeserializeObject <Message>(json);

                    Device dev = context.Devices.FirstOrDefault((item) => item.Text == msg.DeviceId);

                    dev.Messages.Add(msg);


                    context.SaveChanges();


                    return("success");
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Exemple #26
0
        public async Task <List <MotherLibrary.Task> > ListTaskAsync(String userName)
        {
            using (var db = new MyDatabaseContext())
            {
                var currentUser = await db.Users.SingleOrDefaultAsync(m => m.UserName == userName);

                if (currentUser != null)
                {
                    var tasks = await db.Tasks.ToListAsync();

                    var count = tasks.Count;

                    foreach (MotherLibrary.Task task in tasks)
                    {
                        if (task.UserId != currentUser.Id)
                        {
                            tasks.Remove(task);
                        }
                    }

                    return(tasks);
                }
                else
                {
                    return(null);
                }
            }
        }
 public WeatherForecastController(ILogger <WeatherForecastController> logger, MyDatabaseContext context, IHubContext <StudentHub> hub, IBackgroundQueue queue)
 {
     _logger  = logger;
     _context = context;
     _hub     = hub;
     _queue   = queue;
 }
Exemple #28
0
 public async Task <List <MotherLibrary.Task> > ListTasksAsync()
 {
     using (var db = new MyDatabaseContext())
     {
         return(await db.Tasks.ToListAsync());
     }
 }
Exemple #29
0
 public List <Course> ListAllCourses()
 {
     using (var context = new MyDatabaseContext())
     {
         return(context.Courses.ToList());
     }
 }
Exemple #30
0
        public void ShouldListRecipes()
        {
            //SETUP
            var options = SqliteInMemory
                          .CreateOptions <MyDatabaseContext>();
            var numRecipes = 5;

            using (var context = new MyDatabaseContext(options))
            {
                context.Database.EnsureCreated();
                for (var i = 0; i < numRecipes; i++)
                {
                    var r = new Recipe
                    {
                        Dish             = $"Cup of tea #{i}",
                        Description      = $"Boil water and add tea for {i} minute(s) ",
                        MinutesToPrepare = i,
                        QualityStars     = i,
                    };

                    context.Recipes.Add(r);
                }
                context.SaveChanges();

                //ATTEMPT
                var service = new ListRecipesService(context);
                var dtos    = service.SelectAll().ToList();

                //VERIFY
                dtos.Count.ShouldEqual(numRecipes);
            }
        }