示例#1
0
 protected override void Seed(VideoDb context)
 {
     context.Videos.AddOrUpdate(v => v.Title,
                                new Video()
     {
         Title = "MVC", Length = 120
     },
                                new Video()
     {
         Title = "LINQ", Length = 200
     }
                                );
 }
        public async Task <Unit> Handle(UpdateVideoFragmentInterval request, CancellationToken cancellationToken)
        {
            var interval = request.Interval;
            var videoDb  =
                await VideoDb.GetByNameAndUserGuidAsync(DbContext, request.UserGuid, interval.FileName, cancellationToken);

            if (videoDb == null)
            {
                return(Unit.Value);
            }
            videoDb.UpdateProperty(DbContext, nameof(videoDb.StartTime), interval.StartTime);
            videoDb.UpdateProperty(DbContext, nameof(videoDb.EndTime), interval.EndTime);
            await DbContext.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
示例#3
0
 private void BtnSubmit_Click(object sender, EventArgs e)
 {
     if (IsValidData())
     {
         Customer customer = new Customer();
         PutcustomerData(customer);
         try
         {
             LblDisplayMessage.Text = VideoDb.AddCustomer(customer);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
 }
示例#4
0
        public async Task <Unit> Handle(RemoveVideo request, CancellationToken cancellationToken)
        {
            var videoDb =
                await VideoDb.GetByNameAndUserGuidAsync(DbContext, request.UserGuid, request.FileName, cancellationToken);

            if (videoDb == null)
            {
                return(Unit.Value);
            }
            var watchedVideos = DbContext.WatchedVideos.Where(view => view.VideoId == view.Id);

            DbContext.WatchedVideos.RemoveRange(watchedVideos);
            DbContext.Videos.Remove(videoDb);
            await DbContext.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
 private void txtCustomerID_Validating(object sender, CancelEventArgs e)
 {
     //This method is to check if the customerID exists in database
     try
     {
         int ID = Convert.ToInt32(txtCustomerID.Text);
         customer = VideoDb.SelectCustomer_by_ID(ID);
         if (customer == null)
         {
             MessageBox.Show("No customer found with this ID. " + "Please try again.", "Customer Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 private void GetCustomer_by_Fname_Surname(string firstname, string surname)
 {
     try
     {
         customer = VideoDb.SelectCustomer_by_Fname_Sname(firstname, surname);
         if (customer == null)
         {
             MessageBox.Show("No customer found with this ID. " + "Please try again.", "Customer Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             Displaycustomer();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public IActionResult uploadVideo(Video video)
        {
            int accountid = Convert.ToInt32(SessionHelper.WhosLoggedIn(_accessor));

            video.AccountId = accountid;

            ModelState.Remove(nameof(Video.ThumbnailUrl));

            if (ModelState.IsValid)
            {
                IFormFile thumbnail = video.Thumbnail;

                string extension = Path.GetExtension(thumbnail.FileName);
                if (extension == ".png" || extension == ".jpg")
                {
                    //Use ImageSharp to resize image if needed
                    //https://www.hanselman.com/blog/HowDoYouUseSystemDrawingInNETCore.aspx

                    string newFileName = Guid.NewGuid().ToString();

                    if (thumbnail.Length > 0)
                    {
                        string filePath = Path.Combine(_env.WebRootPath, "images", newFileName + extension);

                        video.ThumbnailUrl = "images/" + newFileName + extension;

                        VideoDb.addVideo(video);

                        using (FileStream fs = new FileStream(filePath, FileMode.Create))
                        {
                            thumbnail.CopyTo(fs);
                        }
                        return(RedirectToAction("MyVideos", "Account"));
                    }

                    return(View());
                }
            }

            return(View());
        }
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            Customer newCustomer = new Customer();

            PutcustomerData(newCustomer);
            try
            {
                bool confirmation = VideoDb.UpdateCustomer(newCustomer, customer);
                if (confirmation == true)
                {
                    MessageBox.Show("Customer details has been successfully updated.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (confirmation == false)
                {
                    MessageBox.Show("Another user has updated or " + "deleted that vendor.", "Database Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                }
                Disable_all_form_control();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public VideoController(VideoDb Vdb)
 {
     videoDb = Vdb;
 }
示例#10
0
 public VideosController()
 {
     db = new VideoDb();
     db.Configuration.ProxyCreationEnabled = false;
 }
示例#11
0
 public VideosController()
 {
     db = new VideoDb();
     db.Configuration.ProxyCreationEnabled = false; //turn of lazy loading, because in webapi typically we immediatly serialize and return the result
 }