示例#1
0
        public async Task <IActionResult> Editkurs(AddUrokViewModel model)
        {
            string path_Root = _appEnvironment.WebRootPath;

            var kur = await db.Kurs.FirstOrDefaultAsync(x => x.Id == model.Id);

            string mat1;
            string mat2;
            string mat3;
            string mat4;

            if (model.mat1 != null && model.mat1.Length != 0)
            {
                mat1     = model.mat1.FileName;
                kur.mat1 = mat1;
                string path_to_mat1 = path_Root + "\\Kurs\\" + mat1;
                using (var stream = new FileStream(path_to_mat1, FileMode.Create))
                {
                    await model.mat1.CopyToAsync(stream);
                }
            }


            if (model.mat2 != null && model.mat2.Length != 0)
            {
                mat2     = model.mat2.FileName;
                kur.mat2 = mat2;
                string path_to_mat2 = path_Root + "\\Kurs\\" + mat2;
                using (var stream = new FileStream(path_to_mat2, FileMode.Create))
                {
                    await model.mat2.CopyToAsync(stream);
                }
            }

            if (model.mat3 != null && model.mat3.Length != 0)
            {
                mat3     = model.mat3.FileName;
                kur.mat3 = mat3;
                string path_to_mat3 = path_Root + "\\Kurs\\" + mat3;
                using (var stream = new FileStream(path_to_mat3, FileMode.Create))
                {
                    await model.mat3.CopyToAsync(stream);
                }
            }

            if (model.mat4 != null && model.mat4.Length != 0)
            {
                mat4     = model.mat4.FileName;
                kur.mat4 = mat4;
                string path_to_mat4 = path_Root + "\\Kurs\\" + mat4;
                using (var stream = new FileStream(path_to_mat4, FileMode.Create))
                {
                    await model.mat4.CopyToAsync(stream);
                }
            }
            if (model.video != null && model.video.Length != 0)
            {
                //var videoname = model.video.FileName;
                //string path_to_Videos = path_Root + "\\Kurs\\" + videoname;
                //using (var stream = new FileStream(path_to_Videos, FileMode.Create))
                //{
                //    await model.video.CopyToAsync(stream);
                //}
                kur.video = model.video;
            }

            if (model.photo != null && model.photo.Length != 0)
            {
                var imgname = model.photo.FileName;

                string path_to_Images = path_Root + "\\Kurs\\" + imgname;

                using (var stream = new FileStream(path_to_Images, FileMode.Create))
                {
                    await model.photo.CopyToAsync(stream);
                }
                kur.photo = imgname;
            }
            kur.subject = model.subject;
            kur.text    = model.text;

            kur.course_id = model.course;

            kur.time = model.time;
            await db.SaveChangesAsync();


            return(RedirectToAction("Kurs", new { id = model.Id }));
        }
示例#2
0
        public async Task <IActionResult> AddKurs(AddUrokViewModel model)
        {
            string path_Root = _appEnvironment.WebRootPath;

            if (model.video == null || model.video.Length == 0)
            {
                return(Content("video not found"));
            }
            if (model.photo == null || model.photo.Length == 0)
            {
                return(Content("photo not found"));
            }
            string mat1 = null;
            string mat2 = null;
            string mat3 = null;
            string mat4 = null;

            if (model.mat1 != null && model.mat1.Length != 0)
            {
                mat1 = model.mat1.FileName;
                string path_to_mat1 = path_Root + "\\Kurs\\" + mat1;
                using (var stream = new FileStream(path_to_mat1, FileMode.Create))
                {
                    await model.mat1.CopyToAsync(stream);
                }
            }

            if (model.mat2 != null && model.mat2.Length != 0)
            {
                mat2 = model.mat2.FileName;
                string path_to_mat2 = path_Root + "\\Kurs\\" + mat2;
                using (var stream = new FileStream(path_to_mat2, FileMode.Create))
                {
                    await model.mat2.CopyToAsync(stream);
                }
            }

            if (model.mat3 != null && model.mat3.Length != 0)
            {
                mat3 = model.mat3.FileName;
                string path_to_mat3 = path_Root + "\\Kurs\\" + mat3;
                using (var stream = new FileStream(path_to_mat3, FileMode.Create))
                {
                    await model.mat3.CopyToAsync(stream);
                }
            }

            if (model.mat4 != null && model.mat4.Length != 0)
            {
                mat4 = model.mat4.FileName;
                string path_to_mat4 = path_Root + "\\Kurs\\" + mat4;
                using (var stream = new FileStream(path_to_mat4, FileMode.Create))
                {
                    await model.mat4.CopyToAsync(stream);
                }
            }

            // var videoname = model.video.FileName;
            var imgname = model.photo.FileName;

            string path_to_Images = path_Root + "\\Kurs\\" + imgname;

            // string path_to_Videos = path_Root + "\\Kurs\\" + videoname;
            using (var stream = new FileStream(path_to_Images, FileMode.Create))
            {
                await model.photo.CopyToAsync(stream);
            }
            //using (var stream = new FileStream(path_to_Videos, FileMode.Create))
            //{
            //    await model.video.CopyToAsync(stream);
            //}

            await db.Kurs.AddAsync(new Kurs
            {
                course_id = model.course,
                subject   = model.subject,
                text      = model.text,
                video     = model.video,
                time      = model.time,
                photo     = imgname,
                mat1      = mat1,
                mat2      = mat2,
                mat3      = mat3,
                mat4      = mat4
            });

            await db.SaveChangesAsync();


            return(RedirectToAction(nameof(Kurses)));
        }