Ejemplo n.º 1
0
        public long AddNewFtpCredential(FtpCredentialCreateEditModel model)
        {
            var dto = _mapper.Map <FtpCredential>(model);

            dto.MasterAccounts.Clear();

            if (_ftpCredentialRepository.IsExists(dto))
            {
                throw new FtpCredentialAlreadyExistsException();
            }

            model.MasterAccounts.ToList().ForEach(acc =>
            {
                var masterAcc = _masterAccountRepository.GetById(acc.Id);
                if (masterAcc == null)
                {
                    throw new MasterAccountNotFoundException();
                }
                dto.MasterAccounts.Add(masterAcc);
            });

            dto = _ftpCredentialRepository.Add(dto);

            return(dto.Id);
        }
Ejemplo n.º 2
0
        public long UpdateFtpCredential(FtpCredentialCreateEditModel model)
        {
            var dto = _ftpCredentialRepository.GetById(model.Id);

            if (dto == null)
            {
                throw new FtpCredentialNotFoundException();
            }

            dto.FtpName      = model.FtpName;
            dto.UserName     = model.UserName;
            dto.UserPassword = model.UserPassword;
            dto.Url          = model.Url;

            var exists        = dto.MasterAccounts.Select(acc => acc.Id).ToList();
            var newMasterAccs = model.MasterAccounts.Select(acc => acc.Id).ToList();
            var forDeleting   = exists.Except(newMasterAccs).ToList();
            var forAdding     = newMasterAccs.Except(exists).ToList();

            forDeleting.ForEach(id =>
            {
                var account = dto.MasterAccounts.FirstOrDefault(acc => acc.Id == id);
                if (account == null)
                {
                    throw new MasterAccountNotFoundException();
                }

                dto.MasterAccounts.Remove(account);
            });

            forAdding.ForEach(id =>
            {
                var account = _masterAccountRepository.GetById(id);
                if (account == null)
                {
                    throw new MasterAccountNotFoundException();
                }

                dto.MasterAccounts.Add(account);
            });

            dto = _ftpCredentialRepository.Update(dto);

            return(dto.Id);
        }
Ejemplo n.º 3
0
 public IHttpActionResult UpdateFtpCredential(FtpCredentialCreateEditModel model)
 {
     return(Ok(_ftpCredentialService.UpdateFtpCredential(model)));
 }