Example #1
0
        public async Task <IActionResult> Create([FromForm] DTO.File file)
        {
            try
            {
                byte[] content;
                using (MemoryStream stream = new MemoryStream())
                {
                    file.LogFile.CopyTo(stream);
                    content = stream.ToArray();
                }
                string response = await ApiClientHelper.ExecuteMultipartPostAsync($"{ApiClientHelper.FileUploadUrl}", content);

                DTO.Import import = JsonConvert.DeserializeObject <DTO.Import>(response);
                messageType = "success";
                message     = $"File imported with {import.SuccessCount} rows successfuly processed, and {import.ErrorCount} rows with error.";
            }
            catch (Exception ex)
            {
                messageType = "error";
                message     = $"Something went wrong: {ex.Message}";
            }
            finally
            {
                ((Controller)this).DisplayTempData(messageType, message);
            }
            return(RedirectToAction("Index"));
        }
        /// <summary>
        /// Generates a <see cref="DTO.Thing"/> from the current <see cref="File"/>
        /// </summary>
        public override DTO.Thing ToDto()
        {
            var dto = new DTO.File(this.Iid, this.RevisionNumber);

            dto.Category.AddRange(this.Category.Select(x => x.Iid));
            dto.ExcludedDomain.AddRange(this.ExcludedDomain.Select(x => x.Iid));
            dto.ExcludedPerson.AddRange(this.ExcludedPerson.Select(x => x.Iid));
            dto.FileRevision.AddRange(this.FileRevision.Select(x => x.Iid));
            dto.LockedBy        = this.LockedBy != null ? (Guid?)this.LockedBy.Iid : null;
            dto.ModifiedOn      = this.ModifiedOn;
            dto.Owner           = this.Owner != null ? this.Owner.Iid : Guid.Empty;
            dto.RevisionNumber  = this.RevisionNumber;
            dto.ThingPreference = this.ThingPreference;

            dto.IterationContainerId = this.CacheKey.Iteration;
            dto.RegisterSourceThing(this);
            this.BuildDtoPartialRoutes(dto);
            return(dto);
        }