Esempio n. 1
0
        public async Task <IActionResult> Create([FromBody] WorkLocationSaveDto resourceSave)
        {
            _auditTrailRepo.User = User;
            var activity  = Validator.GenerateActivity(resourceSave, TransactionType.ADD);
            var validator = await _validator.Validate(resourceSave);

            if (validator.HasError)
            {
                await _auditTrailRepo.SaveFailedTrail(new AuditTrailFailedSaveDto()
                {
                    Action       = TransactionType.ADD,
                    Activity     = activity,
                    ErrorMessage = validator.Message
                });

                return(BadRequest(validator.Message));
            }
            var workLocation = _mapper.Map <WorkLocation>(resourceSave);

            _crudPattern.Create(workLocation);

            if (!await _crudPattern.SaveChanges())
            {
                return(BadRequest("Nothing has been Saved!"));
            }


            await _auditTrailRepo.SaveSuccessTrail(new AuditTrailSuccessSaveDto()
            {
                Action   = TransactionType.ADD,
                Activity = activity
            });

            return(StatusCode(201));
        }
        public async Task <IActionResult> Create([ModelBinder(BinderType = typeof(JsonModelBinder))][FromBody] CustomerSaveDto resourceSave, IFormFile profilePictureFile)
        {
            _auditTrailRepo.User = User;
            var activity  = Validator.GenerateActivity(resourceSave, TransactionType.ADD);
            var validator = await _validator.Validate(resourceSave);

            if (validator.HasError)
            {
                await _auditTrailRepo.SaveFailedTrail(new AuditTrailFailedSaveDto()
                {
                    Action       = TransactionType.ADD,
                    Activity     = activity,
                    ErrorMessage = validator.Message
                });

                return(BadRequest(validator.Message));
            }
            var customer = _mapper.Map <Customer>(resourceSave);

            _crudPattern.Create(customer);
            var newFileName = $"{Guid.NewGuid()}{Path.GetExtension(profilePictureFile.FileName)}";

            customer.ProfilePictureFileName = newFileName;

            if (!await _crudPattern.SaveChanges())
            {
                return(BadRequest("Nothing has been Saved!"));
            }

            await _blobStorageRepo.UploadFile(profilePictureFile, newFileName);


            await _auditTrailRepo.SaveSuccessTrail(new AuditTrailSuccessSaveDto()
            {
                Action   = TransactionType.ADD,
                Activity = activity
            });

            return(StatusCode(201));
        }