Esempio n. 1
0
        public TMSEmployee Add(TMSEmployeeCreateViewModel Vm)
        {
            var key       = "E546C8DF278CD5931069B522E695D4F2";
            var encrypted = EncryptString(Vm.Password, key);

            Vm.Password = encrypted;
            var entity = _mapper.Map <TMSEmployeeCreateViewModel, TMSEmployee>(Vm);

            _iTMSEmployeeRepository.Add(entity);
            SaveChanges();
            return(entity);
        }
Esempio n. 2
0
        public IActionResult Add([FromBody] TMSEmployeeCreateViewModel Vm)
        {
            if (!ModelState.IsValid)
            {
                var allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(new GenericResult(false, allErrors)));
            }
            else
            {
                try
                {
                    _iTMSEmployeeService.Add(Vm);

                    return(new OkObjectResult(new GenericResult(true, "Add success!!!")));
                }
                catch (Exception ex)
                {
                    return(new OkObjectResult(new GenericResult(false, ex.Message)));
                }
            }
        }