Exemple #1
0
        public async Task <IHttpActionResult> PutxType(int id, xType xType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != xType.TypeID)
            {
                return(BadRequest());
            }

            db.Entry(xType).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!xTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        /// <summary>
        /// Instantiator; sets the m_app and m_wkbk object properties based on the path and file
        /// </summary>
        /// <param name="pathAndFile">Full path and and name of file to read/create</param>
        /// <param name="overwrite">When TRUE, file will be deleted if it exists.  Leave this False if you are reading a file!</param>
        public XL(string pathAndFile, Boolean overwrite = false)
        {
            try
            {
                string extension = pathAndFile.Split('.')[pathAndFile.Split('.').GetUpperBound(0)].ToLower();
                switch (extension)
                {
                case "xls":
                    m_type     = xType.xls;
                    m_firstRow = 0;
                    m_firstCol = 0;
                    break;

                case "xlsx":
                    m_firstRow = 1;
                    m_firstCol = 1;
                    m_type     = xType.xlsx;
                    break;

                default:
                    m_errMsg = "Invalid File Name: You must provide a file name that ends in either .xls or .xlsx.";
                    return;
                }
                FileInfo f = new FileInfo(@pathAndFile);
                if (f.Exists && overwrite)
                {
                    f.Delete();
                    f = new FileInfo(pathAndFile);
                }

                switch (m_type)
                {
                case xType.xls:
                    using (FileStream fstream = new FileStream(f.FullName, FileMode.Open, FileAccess.Read))
                    {
                        //Note NPOI has no 'application' equivalent object, so m_app stays null.
                        //We start directly from a workbook object
                        HSSFWorkbook wb = new HSSFWorkbook(fstream);
                        m_wkbk = wb;
                    }
                    break;

                case xType.xlsx:
                    ExcelPackage xlsx = new ExcelPackage(f);
                    m_app    = xlsx;
                    m_wkbk   = ((ExcelPackage)m_app).Workbook;
                    m_wkshts = ((OfficeOpenXml.ExcelWorkbook)m_wkbk).Worksheets;
                    break;

                default:
                    m_app = null;
                    break;
                }
            } catch (Exception ex)
            {
                m_errMsg = ex.Message + AAAK.vbCRLF + ex.StackTrace;
            }
        }
Exemple #3
0
        public async Task <IHttpActionResult> GetxType(int id)
        {
            xType xType = await db.Types.FindAsync(id);

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

            return(Ok(xType));
        }
Exemple #4
0
        public async Task <IHttpActionResult> PostxType(xType xType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Types.Add(xType);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = xType.TypeID }, xType));
        }
Exemple #5
0
        public async Task <IHttpActionResult> DeletexType(int id)
        {
            xType xType = await db.Types.FindAsync(id);

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

            db.Types.Remove(xType);
            await db.SaveChangesAsync();

            return(Ok(xType));
        }