Example #1
0
        public virtual async Task <JsonResult> Update(int id)
        {
            var findRep = await _relativeSrv.FindWithAttachmentsAsync(id);

            if (!findRep.IsSuccessful)
            {
                return(Json(new { IsSuccessful = false, Message = Strings.RecordNotFound.Fill(DomainString.Relatives) }));
            }
            if (findRep.Result.RelativeAttachments != null)
            {
                foreach (var item in findRep.Result.RelativeAttachments)
                {
                    item.Url = $"{_configuration["CustomSettings:MainAddress"]}{item.Url}";
                }
            }

            return(Json(new Modal
            {
                Title = $"{Strings.Update} {DomainString.Relatives}",
                AutoSubmitBtnText = Strings.Edit,
                Body = ControllerExtension.RenderViewToString(this, "Partials/_Entity", findRep.Result),
                AutoSubmit = false,
                ResetForm = false
            }));
        }
Example #2
0
        public async Task <ActionResult> DownloadAllAttachments(Guid id)
        {
            var user = await _userSrv.FindWithAttachmentsAsync(id);

            using (var memoryStream = new MemoryStream())
            {
                using (var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                {
                    foreach (var attchment in user.Result.UserAttachments)
                    {
                        try
                        {
                            var filePath    = $"wwwroot/{attchment.Url}";
                            var fileContent = await System.IO.File.ReadAllBytesAsync(filePath);


                            var zipArchiveEntry = zipArchive.CreateEntry($"CustomerAttachments/{Path.GetFileName(filePath)}", CompressionLevel.Optimal);
                            using (var zipStream = zipArchiveEntry.Open())
                                zipStream.Write(fileContent, 0, fileContent.Length);
                        }
                        catch (Exception e) { }
                    }

                    foreach (var relative in user.Result.Relatives)
                    {
                        var userRelative = await _relativeSrv.FindWithAttachmentsAsync(relative.RelativeId);

                        foreach (var attchment in userRelative.Result.RelativeAttachments)
                        {
                            try
                            {
                                var filePath    = $"wwwroot/{attchment.Url}";
                                var fileContent = await System.IO.File.ReadAllBytesAsync(filePath);


                                var zipArchiveEntry = zipArchive.CreateEntry($"CustomerRelativesAttachments/{relative.NationalCode}/{Path.GetFileName(filePath)}", CompressionLevel.Optimal);
                                using (var zipStream = zipArchiveEntry.Open())
                                    zipStream.Write(fileContent, 0, fileContent.Length);
                            }
                            catch (Exception e) { }
                        }
                    }
                }

                return(File(memoryStream.ToArray(), "application/zip", $"{user.Result.NationalCode}-{user.Result.MobileNumber}.zip"));
            }
        }