Exemple #1
0
        public async Task <IActionResult> CreateAuditRecD([FromBody] AuditRecDDto auditRecDDto)
        {
            var auditRecM = await _auditRecMService.GetRecMById(auditRecDDto.Record_ID);

            var auditRecD = await _service.GetById(auditRecDDto.Record_ID);

            if (auditRecD != null)
            {
                auditRecDDto.Item_no = auditRecD.Item_no + 1;
            }
            else
            {
                auditRecDDto.Item_no = 1;
            }
            var username = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            auditRecDDto.Updated_By     = username;
            auditRecDDto.Implement_User = username;
            string folder = _webHostEnvironmentl.WebRootPath + "\\uploaded\\images";

            if (auditRecDDto.Before_Picture != "")
            {
                var    source = auditRecDDto.Before_Picture;
                string base64 = source.Substring(source.IndexOf(',') + 1);
                base64 = base64.Trim('\0');
                byte[] charData = Convert.FromBase64String(base64);
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                var    fileName   = auditRecM.Record_ID + "_" + auditRecM.Line + "_" + auditRecM.Model_No + "_B4_" + auditRecDDto.Item_no + ".jpg";
                string filePathB4 = Path.Combine(folder, fileName);
                System.IO.File.WriteAllBytes(filePathB4, charData);
                auditRecDDto.Before_Picture = fileName;
            }

            if (auditRecDDto.After_Picture != "")
            {
                var    source   = auditRecDDto.After_Picture;
                string base64   = source.Substring(source.IndexOf(',') + 1);
                byte[] charData = Convert.FromBase64String(base64);
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                var    fileName      = auditRecM.Record_ID + "_" + auditRecM.Line + "_" + auditRecM.Model_No + "_After_" + auditRecDDto.Item_no + ".jpg";
                string filePathAfter = Path.Combine(folder, fileName);
                System.IO.File.WriteAllBytes(filePathAfter, charData);
                auditRecDDto.After_Picture = fileName;
            }

            if (await _service.AddRecD(auditRecDDto))
            {
                return(NoContent());
            }

            throw new Exception("Creating the Audit Rec D failed on save");
        }
Exemple #2
0
        public async Task <IActionResult> AddRecD([FromBody] AuditRecDViewModel model)
        {
            var username = User.FindFirst(ClaimTypes.Name).Value;

            model.Updated_By = username;
            if (await _service.AddRecD(model))
            {
                return(CreatedAtRoute("GetAllRecDs", new { }));
            }
            throw new Exception("Creating the Audit RecD failed on save");
        }