Ejemplo n.º 1
0
        public IActionResult AddRateByExcel(int id, int PolicyYear, [FromForm(Name = "file")] IFormFile formFile)
        {
            try
            {
                if (formFile == null || formFile.Length <= 0)
                {
                    return(BadRequest(new { error = "file is empty" }));
                }


                if (!Path.GetExtension(formFile.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
                {
                    if (!Path.GetExtension(formFile.FileName).Equals(".xls", StringComparison.OrdinalIgnoreCase))
                    {
                        return(BadRequest(new { error = "Not Support file extension" }));
                    }
                }


                using (var stream = new MemoryStream())
                {
                    formFile.CopyTo(stream);
                    var data = _itemService.UploadRatesByAge(id, PolicyYear, stream, GetNameClaim());
                    //var data = _itemService.UpLoadRate(InsuranceCompanyId, PolicyYear, stream);
                    return(Ok(data));
                }

                // add list to db ..
                // here just read and return
            }

            catch (AppException ex)
            {
                return(DefaultError(ex.Message));
            }
        }