public async Task <AttachmentForm> UpdateAsync(AttachmentForm entity, CancellationToken cancellationToken)
        {
            db.AttachmentForms.Update(entity);
            await db.SaveChangesAsync(cancellationToken);

            return(entity);
        }
Esempio n. 2
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            AttachmentForm form = new AttachmentForm(_letterId);

            form.ShowDialog();
            fillGrid();
        }
Esempio n. 3
0
        private void MockData(
            Form form = default,
            AttachmentForm attachmentForm = default,
            IEnumerable <Form> formList   = default,
            IEnumerable <AttachmentForm> attachmentFormList = default,
            ValidationModel <Form> validationForm           = default
            )
        {
            _dataForm.Setup(x => x.GetAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(form);
            _dataForm.Setup(x => x.GetAllAsync(It.IsAny <CancellationToken>())).ReturnsAsync(formList);
            _dataForm.Setup(x => x.InsertAsync(It.IsAny <Form>(), It.IsAny <CancellationToken>())).ReturnsAsync(form);
            _dataForm.Setup(x => x.UpdateAsync(It.IsAny <Form>(), It.IsAny <CancellationToken>())).ReturnsAsync(form);
            _dataForm.Setup(x => x.DeleteAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()));

            _dataAttachmentForm.Setup(x => x.GetAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(attachmentForm);
            _dataAttachmentForm.Setup(x => x.GetAllAsync(It.IsAny <CancellationToken>())).ReturnsAsync(attachmentFormList);
            _dataAttachmentForm.Setup(x => x.InsertAsync(It.IsAny <AttachmentForm>(), It.IsAny <CancellationToken>())).ReturnsAsync(attachmentForm);
            _dataAttachmentForm.Setup(x => x.UpdateAsync(It.IsAny <AttachmentForm>(), It.IsAny <CancellationToken>())).ReturnsAsync(attachmentForm);
            _dataAttachmentForm.Setup(x => x.DeleteAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()));

            _formValidation.Setup(x => x.GetValidationAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(validationForm);
            _formValidation.Setup(x => x.InsertValidationAsync(It.IsAny <Form>(), It.IsAny <CancellationToken>())).ReturnsAsync(validationForm);
            _formValidation.Setup(x => x.UpdateValidationAsync(It.IsAny <Form>(), It.IsAny <CancellationToken>())).ReturnsAsync(validationForm);
            _formValidation.Setup(x => x.DeleteValidationAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(validationForm);

            _service = new FormService(_fileHelper.Object, _dataForm.Object, _dataAttachmentForm.Object, _formValidation.Object);
        }
Esempio n. 4
0
        public async Task <ValidationModel <AttachmentForm> > UpdateValidationAsync(AttachmentForm newEntity, CancellationToken cancellationToken = default)
        {
            if (newEntity is not null)
            {
                if (!await dataAttachmentForm.ExistByIdAsync(newEntity.Id, cancellationToken))
                {
                    validation.Errors.Add(nameof(AttachmentForm),
                                          string.Format(BaseValidation.ObjectNotExistById, nameof(AttachmentForm), newEntity.Id));
                }

                if (!await dataForm.ExistByIdAsync(newEntity.FormId, cancellationToken))
                {
                    validation.Errors.Add(nameof(AttachmentForm.Form),
                                          string.Format(BaseValidation.ObjectNotExistById, nameof(AttachmentForm.Form), newEntity.FormId));
                }

                if (newEntity.File is null)
                {
                    validation.Errors.Add(nameof(AttachmentForm.File),
                                          string.Format(BaseValidation.FileNotCanBeNull));
                }
            }
            else
            {
                validation.Errors.Add(nameof(AttachmentForm),
                                      string.Format(BaseValidation.ObjectNotCanBeNull, nameof(AttachmentForm)));
            }

            return(validation);
        }
Esempio n. 5
0
        public async Task UpdateValidationAsync_Null_UnSucces()
        {
            // Arrange
            MockData(
                isExsitAttachmentFormById: false,
                isExsitFormById: false
                );
            AttachmentForm entity    = null;
            var            listError = new Dictionary <string, string>()
            {
                { nameof(AttachmentForm), string.Format(BaseValidation.ObjectNotCanBeNull, nameof(AttachmentForm)) }
            };

            // Act
            var result = await _validation.UpdateValidationAsync(entity);

            // Assert
            Assert.Multiple(() =>
            {
                Assert.NotNull(result.Errors);
                Assert.IsNotEmpty(result.Errors);
                Assert.IsFalse(result.IsValid);
                foreach (var error in result.Errors)
                {
                    Assert.IsTrue(listError.ContainsKey(error.Key));
                    Assert.AreEqual(listError[error.Key], error.Value);
                }
            });
        }
Esempio n. 6
0
        private void MockData(
            AttachmentForm attachmentForm = default,
            IEnumerable <AttachmentForm> attachmentFormList           = default,
            ValidationModel <AttachmentForm> validationAttachmentForm = default
            )
        {
            _fileHelper.Setup(x => x.SaveFile(It.IsAny <IFormFile>()))
            .ReturnsAsync(GetFileModelByAttachmentForm(attachmentForm));
            _fileHelper.Setup(x => x.SaveFileRange(It.IsAny <IList <IFormFile> >()))
            .ReturnsAsync(GetFileModelListByAttachmentForm(attachmentFormList));
            _fileHelper.Setup(x => x.DeleteFile(It.IsAny <string>()));

            _dataAttachmentForm.Setup(x => x.GetAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(attachmentForm);
            _dataAttachmentForm.Setup(x => x.GetAllAsync(It.IsAny <CancellationToken>())).ReturnsAsync(attachmentFormList);
            _dataAttachmentForm.Setup(x => x.InsertAsync(It.IsAny <AttachmentForm>(), It.IsAny <CancellationToken>())).ReturnsAsync(attachmentForm);
            _dataAttachmentForm.Setup(x => x.UpdateAsync(It.IsAny <AttachmentForm>(), It.IsAny <CancellationToken>())).ReturnsAsync(attachmentForm);
            _dataAttachmentForm.Setup(x => x.DeleteAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>()));

            _attachmentFormValidation.Setup(x => x.GetValidationAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(validationAttachmentForm);
            _attachmentFormValidation.Setup(x => x.InsertValidationAsync(It.IsAny <AttachmentForm>(), It.IsAny <CancellationToken>())).ReturnsAsync(validationAttachmentForm);
            _attachmentFormValidation.Setup(x => x.UpdateValidationAsync(It.IsAny <AttachmentForm>(), It.IsAny <CancellationToken>())).ReturnsAsync(validationAttachmentForm);
            _attachmentFormValidation.Setup(x => x.DeleteValidationAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(validationAttachmentForm);

            _service = new AttachmentFormService(_fileHelper.Object, _dataAttachmentForm.Object, _attachmentFormValidation.Object);
        }
Esempio n. 7
0
        public async Task <ValidationModel <Form> > InsertAsync(Form newEntity, CancellationToken cancellationToken = default)
        {
            var validation = await formValidation.InsertValidationAsync(newEntity, cancellationToken);

            if (!validation.IsValid)
            {
                return(validation);
            }


            newEntity.CreatedAt = DateTime.Now;
            newEntity.UpdatedAt = DateTime.Now;

            validation.Result = await dataForm.InsertAsync(newEntity, cancellationToken);

            if (newEntity.Files is not null && !newEntity.Files.Count().Equals(0))
            {
                var fileDatas = await fileHelper.SaveFileRange(newEntity.Files);

                foreach (var file in fileDatas)
                {
                    var attachmentForm = new AttachmentForm()
                    {
                        FilePath = file.FilePath,
                        FileName = file.FileName,
                        FileType = file.FileType,
                        FormId   = validation.Result.Id
                    };

                    await dataAttachmentForm.InsertAsync(attachmentForm, cancellationToken);
                }
            }

            return(validation);
        }
Esempio n. 8
0
 private void uiAttachmentToolStripButton_Click(object sender, EventArgs e)
 {
     using (AttachmentForm attachment = new AttachmentForm())
     {
         attachment.ShowDialog();
     }
 }
        public async Task <AttachmentForm> InsertAsync(AttachmentForm entity, CancellationToken cancellationToken)
        {
            await db.AttachmentForms.AddAsync(entity, cancellationToken);

            await db.SaveChangesAsync(cancellationToken);

            return(entity);
        }
 public async Task <bool> ExistAsync(AttachmentForm entity, CancellationToken cancellationToken)
 {
     return(await db.AttachmentForms.AnyAsync(db =>
                                              db.FileName == entity.FileName &&
                                              db.FileType == entity.FileType &&
                                              db.FilePath == entity.FilePath,
                                              cancellationToken));
 }
Esempio n. 11
0
 private FileModel GetFileModelByAttachmentForm(AttachmentForm attachmentForm = default)
 {
     return(new FileModel()
     {
         FileName = attachmentForm.FileName,
         FilePath = attachmentForm.FilePath,
         FileType = attachmentForm.FileType
     });
 }
Esempio n. 12
0
        public async Task <ValidationModel <AttachmentForm> > InsertValidationAsync(AttachmentForm newEntity, CancellationToken cancellationToken = default)
        {
            if (newEntity is not null)
            {
                if (newEntity.File is null)
                {
                    validation.Errors.Add(nameof(AttachmentForm.File),
                                          string.Format(BaseValidation.FileNotCanBeNull));
                }
            }
            else
            {
                validation.Errors.Add(nameof(AttachmentForm),
                                      string.Format(BaseValidation.ObjectNotCanBeNull, nameof(AttachmentForm)));
            }

            return(validation);
        }
Esempio n. 13
0
        public async Task <ValidationModel <AttachmentForm> > UpdateAsync(AttachmentForm newEntity, CancellationToken cancellationToken = default)
        {
            var validation = await attachmentFormValidation.UpdateValidationAsync(newEntity, cancellationToken);

            if (!validation.IsValid)
            {
                return(validation);
            }

            var oldEntity = await dataAttachmentForm.GetAsync(newEntity.Id, cancellationToken);

            newEntity.CreatedAt = oldEntity.CreatedAt;
            newEntity.UpdatedAt = DateTime.Now;

            validation.Result = await dataAttachmentForm.UpdateAsync(newEntity, cancellationToken);

            return(validation);
        }
        public async Task TestUpdateAsync()
        {
            // Arrange
            var random = new Random(0);
            var number = random.Next(5);
            var entity = GetList()[number];
            await _service.InsertAsync(entity);

            _dbContext.Entry(entity).State      = EntityState.Detached;
            _dbContext.Entry(entity.Form).State = EntityState.Detached;

            entity = new AttachmentForm()
            {
                Id        = entity.Id,
                FormId    = Guid.NewGuid(),
                Form      = GetForm(),
                FileName  = Guid.NewGuid().ToString(),
                CreatedAt = DateTime.Now.AddMinutes(60),
                UpdatedAt = DateTime.Now.AddMinutes(60)
            };
            await _service.UpdateAsync(entity);

            _dbContext.Entry(entity).State      = EntityState.Detached;
            _dbContext.Entry(entity.Form).State = EntityState.Detached;

            // Act
            var result = await _service.GetAsync(entity.Id);

            _dbContext.Entry(result).State      = EntityState.Detached;
            _dbContext.Entry(result.Form).State = EntityState.Detached;

            // Assert
            Assert.Multiple(() =>
            {
                Assert.IsTrue(entity.FileName == result.FileName);
                Assert.IsTrue(entity.FilePath == result.FilePath);
                Assert.IsTrue(entity.FileType == result.FileType);
                Assert.IsTrue(entity.FormId == result.FormId);
                Assert.IsTrue(entity.CreatedAt == result.CreatedAt);
                Assert.IsTrue(entity.UpdatedAt == result.UpdatedAt);
            });
        }
Esempio n. 15
0
        public async Task <ValidationModel <AttachmentForm> > InsertAsync(AttachmentForm newEntity, CancellationToken cancellationToken = default)
        {
            var validation = await attachmentFormValidation.InsertValidationAsync(newEntity, cancellationToken);

            if (!validation.IsValid)
            {
                return(validation);
            }

            var fileData = await fileHelper.SaveFile(newEntity.File);

            newEntity.FilePath  = fileData.FilePath;
            newEntity.FileName  = fileData.FileName;
            newEntity.FileType  = fileData.FileType;
            newEntity.CreatedAt = DateTime.Now;
            newEntity.UpdatedAt = DateTime.Now;

            validation.Result = await dataAttachmentForm.InsertAsync(newEntity, cancellationToken);

            return(validation);
        }
Esempio n. 16
0
        public IActionResult OnGet()
        {
            var username = HttpContext.Session.GetString("_username");
            var usertype = HttpContext.Session.GetString("_usertype");
            var access   = new Access(username, "Coordinator");

            if (access.IsLogin())
            {
                if (access.IsAuthorize(usertype))
                {
                    TypeSelectList = new SelectList(new List <SelectListItem>
                    {
                        new SelectListItem {
                            Text = "All", Value = "All"
                        },
                        new SelectListItem {
                            Text = "Student", Value = "Student"
                        },
                        new SelectListItem {
                            Text = "Supervisor", Value = "Supervisor"
                        },
                    }, "Value", "Text");

                    Af = new AttachmentForm();

                    return(Page());
                }
                else
                {
                    ErrorMessage = "Access Denied";
                    return(RedirectToPage($"/{usertype}/Index"));
                }
            }
            else
            {
                ErrorMessage = "Login Required";
                return(RedirectToPage("/Account/Login"));
            }
        }
Esempio n. 17
0
        public async Task <IActionResult> add([FromForm] AttachmentForm form)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var attachmentUrl = form.fullName + "_" + form.carNumber + form.carEnglishChar;
            var fileUrl       = DateTimeOffset.Now.ToUnixTimeMilliseconds() + "";

            Directory.CreateDirectory(Path.Combine(host, attachmentUrl));
            Directory.CreateDirectory(Path.Combine(host, attachmentUrl, fileUrl));

            var attach = new Attachment()
            {
                nationIdentity       = form.nationIdentity,
                fullName             = form.fullName,
                carArabicChar        = form.carArabicChar,
                carEnglishChar       = form.carEnglishChar,
                carNumber            = form.carNumber,
                drivingLicenseNumber = form.drivingLicenseNumber,
                attachmentUrl        = attachmentUrl,
                fileUrl = fileUrl
            };

            foreach (var itemFile in form.FileList)
            {
                var path = Path.Combine(host, attachmentUrl, fileUrl, itemFile.FileName);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await itemFile.CopyToAsync(stream);
                }
            }

            _context.Attachments.Add(attach);
            _context.SaveChanges();
            return(Ok());
        }