示例#1
0
 public async Task <IActionResult> Update(AuditType_D_Dto auditTypeDto)
 {
     if (await _auditTypeDService.Update(auditTypeDto))
     {
         return(NoContent());
     }
     return(BadRequest($"Updating AuditType {auditTypeDto.Audit_Type_ID} failed on save"));
 }
示例#2
0
        public async Task <IActionResult> Update([FromForm] AuditType_D_Dto auditTypeDto)
        {
            IFormFile filevideo = Request.Form.Files["filevideo"];

            auditTypeDto.Audit_Type_ID  = Request.Form["audit_Type_ID"];
            auditTypeDto.Audit_Item_ID  = Request.Form["audit_Item_ID"];
            auditTypeDto.Audit_Type3_ZW = Request.Form["audit_Type3_ZW"];
            auditTypeDto.Audit_Type3_EN = Request.Form["audit_Type3_EN"];
            auditTypeDto.Audit_Type3_LL = Request.Form["audit_Type3_LL"];
            auditTypeDto.Audit_Item_EN  = Request.Form["audit_Item_EN"];
            auditTypeDto.Audit_Item_LL  = Request.Form["audit_Item_LL"];
            auditTypeDto.Audit_Item_ZW  = Request.Form["audit_Item_ZW"];
            auditTypeDto.Rating_0       = Request.Form["rating_0"].ToInt();
            auditTypeDto.Rating_1       = Request.Form["rating_1"].ToInt();
            auditTypeDto.Rating_2       = Request.Form["rating_2"].ToInt();
            auditTypeDto.Version        = Request.Form["version"].ToInt();
            auditTypeDto.Visible        = Request.Form["visible"].ToBool();
            auditTypeDto.Movie_Name     = Request.Form["movie_Name"];
            string folder = _webHostEnvironment.WebRootPath + "\\uploaded\\video";
            string name   = _auditTypeDService.GetNameVideoByID(auditTypeDto.Audit_Type_ID);
            var    file   = filevideo;

            //kiểm tra có thay đổi video không
            if (filevideo != null)
            {
                var filenameB4 = ContentDispositionHeaderValue
                                 .Parse(file.ContentDisposition)
                                 .FileName
                                 .Trim('"');
                filenameB4 = name + "_" + auditTypeDto.Audit_Item_ID + "_" + Path.GetExtension(filenameB4);
                string filePathB4 = Path.Combine(folder, filenameB4);
                // kiểm tra file cũ có chưa xóa đi
                if (System.IO.File.Exists(filePathB4))
                {
                    System.IO.File.Delete(filePathB4);
                }

                using (FileStream fs = System.IO.File.Create(filePathB4))
                {
                    filevideo.CopyTo(fs);
                    fs.Flush();
                }
                auditTypeDto.Movie_Name = filenameB4;
            }
            var username = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            auditTypeDto.Updated_By   = username;
            auditTypeDto.Updated_Time = DateTime.Now;
            if (await _auditTypeDService.Update(auditTypeDto))
            {
                return(NoContent());
            }
            return(BadRequest($"Updating AuditType {auditTypeDto.Audit_Type_ID} failed on save"));
        }