Esempio n. 1
0
        public async Task <IActionResult> Update(RecordUpdateDTO recordUpdateDTO)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string userName = User.Identity.Name;

                    User user = await _userManager.FindByNameAsync(userName);

                    Record existRecord = await _recordService.GetByIdAsync(recordUpdateDTO.Id);

                    if (recordUpdateDTO.NewFiles != null)
                    {
                        List <UploadedFile> uploadedFileCreateDTOs = AddFiles(recordUpdateDTO.NewFiles, recordUpdateDTO.Id, userName);

                        foreach (var picture in uploadedFileCreateDTOs)
                        {
                            await _uploadedFileService.CreateAsync(picture);
                        }
                    }

                    if (recordUpdateDTO.UploadedFileViewDTOs != null)
                    {
                        foreach (var picture in recordUpdateDTO.UploadedFileViewDTOs)
                        {
                            if (picture.Delete == true)
                            {
                                System.IO.File.Delete(picture.Path);

                                await _uploadedFileService.DeleteAsync(picture.Id);
                            }
                        }
                    }

                    Record recordToUpdate = _mapper.Map <Record>(recordUpdateDTO);

                    recordToUpdate.Text = _aesCryptoProvider.EncryptValue(recordUpdateDTO.DecryptedText, user.CryptoKey, existRecord.IvKey);
                    await _recordService.UpdateEntryAsync(recordToUpdate);
                }
                catch (DbUpdateException ex)
                {
                    return(Content(ex.Message));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }

                return(RedirectToAction("Index", "Home"));
            }

            return(View(recordUpdateDTO));
        }
Esempio n. 2
0
        public ActionResult UpdateRecord(int id, RecordUpdateDTO recordUpdate)
        {
            var record = _repository.GetIdRecord(id);

            if (record == null)
            {
                return(NotFound());
            }
            record.Age      = recordUpdate.Age;
            record.House    = recordUpdate.House.ToString();
            record.Name     = recordUpdate.Name;
            record.LastName = recordUpdate.LastName;
            _repository.SaveChanges();
            return(NoContent());
        }
        public ActionResult UpdateRecord(int id, RecordUpdateDTO updateDTO)
        {
            Record recordFromRepo;

            recordFromRepo = _repo.GetRecordById(id);

            if (recordFromRepo == null)
            {
                return(NotFound());
            }

            _mapper.Map(updateDTO, recordFromRepo);
            _repo.UpdateRecord(recordFromRepo);
            _repo.SaveChanges();

            return(NoContent());
        }
Esempio n. 4
0
        public async Task <IActionResult> Update(Guid id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Record record = await _recordService.GetByIdAsync(id);

            User user = await _userManager.FindByIdAsync(record.UserId.ToString());

            RecordUpdateDTO recordViewDTO = _mapper.Map <RecordUpdateDTO>(record);

            recordViewDTO.DecryptedText = _aesCryptoProvider.DecryptValue(record.Text, user.CryptoKey, record.IvKey);

            recordViewDTO.AbilityToRemove = _checkingAbilityToRemove.Check(record.Created);

            return(View(recordViewDTO));
        }