Ejemplo n.º 1
0
        public async Task <IActionResult> Put([FromForm] FormParentsSalaryModel model)
        {
            var response = await _formService.UpdateParentsSalary(model);

            return(Ok(response));
        }
Ejemplo n.º 2
0
        public async Task <FormParentsSalaryModel> UpdateParentsSalary(FormParentsSalaryModel model)
        {
            var entity = _unitOfWork.Repository <FormParentsSalaryEntity>().Set.FirstOrDefault(x => x.Form.UserId == _authUser.Id);

            if (entity != null)
            {
                entity.MotherName       = model.MotherName;
                entity.FatherName       = model.FatherName;
                entity.FatherDisability = model.FatherDisability;
                entity.MotherDisability = model.MotherDisability;
                entity.LastUpdated      = DateTime.Now;
                model.LastUpdated       = entity.LastUpdated;

                if (!string.IsNullOrEmpty(model.SalarySlips?.FileName))
                {
                    //var name = $"Form_ParentsSalary_{nameof(entity.SalarySlips)}";
                    var oldName = string.IsNullOrEmpty(entity.SalarySlips) ? "" : entity.SalarySlipsDownloadName + entity.SalarySlips.Split('.').LastOrDefault();
                    var newName = await _fileHelper.SaveOrUpdateUserFile(model.SalarySlips, oldName, entity.SalarySlipsDownloadName, _authUser.Id);

                    model.SalarySlipsDownloadName = newName;
                    //entity.SalarySlipsDownloadName = newName;
                    model.SalarySlipsFileName = model.SalarySlips.FileName;
                    entity.SalarySlips        = model.SalarySlips.FileName;

                    model.SalarySlips = null;
                }

                if (!string.IsNullOrEmpty(model.Disability?.FileName))
                {
                    //var name = $"Form_ParentsSalary_{nameof(entity.Disability)}";
                    var oldName = string.IsNullOrEmpty(entity.Disability) ? "" : entity.DisabilityDownloadName + entity.Disability.Split('.').LastOrDefault();
                    var newName = await _fileHelper.SaveOrUpdateUserFile(model.Disability, oldName, entity.DisabilityDownloadName, _authUser.Id);

                    model.DisabilityDownloadName = newName;
                    //entity.SalarySlipsDownloadName = newName;
                    model.DisabilityFileName = model.Disability.FileName;
                    entity.Disability        = model.Disability.FileName;

                    model.Disability = null;
                }

                if (!string.IsNullOrEmpty(model.Disability2?.FileName))
                {
                    //var name = $"Form_ParentsSalary_{nameof(entity.Disability)}";
                    var oldName = string.IsNullOrEmpty(entity.Disability2) ? "" : entity.Disability2DownloadName + entity.Disability2.Split('.').LastOrDefault();
                    var newName = await _fileHelper.SaveOrUpdateUserFile(model.Disability2, oldName, entity.Disability2DownloadName, _authUser.Id);

                    model.Disability2DownloadName = newName;
                    //entity.SalarySlipsDownloadName = newName;
                    model.Disability2FileName = model.Disability2.FileName;
                    entity.Disability2        = model.Disability2.FileName;

                    model.Disability2 = null;
                }

                await _unitOfWork.Repository <FormParentsSalaryEntity>().UpdateAsync(entity);

                return(model);
            }

            return(null);
        }