예제 #1
0
        public ActionResult BatchUpload(DateTime?date, HttpPostedFileBase file, int?fundid, string text)
        {
            if (!date.HasValue)
            {
                ModelState.AddModelError("date", "Date is required");
                return(View("Batch"));
            }
            var    fromFile = false;
            string s;

            if (file != null)
            {
                var buffer = new byte[file.ContentLength];
                file.InputStream.Read(buffer, 0, file.ContentLength);
                System.Text.Encoding enc;
                if (buffer[0] == 0xFF && buffer[1] == 0xFE)
                {
                    enc = new System.Text.UnicodeEncoding();
                    s   = enc.GetString(buffer, 2, buffer.Length - 2);
                }
                else
                {
                    enc = new System.Text.ASCIIEncoding();
                    s   = enc.GetString(buffer);
                }

                fromFile = true;
            }
            else
            {
                if (String.IsNullOrWhiteSpace(text))
                {
                    ModelState.AddModelError("textarea", "Text is required when no file is uploaded.");
                    return(View("Batch"));
                }

                s = text;
            }

            try
            {
                var id = BatchImportContributions.BatchProcess(s, date.Value, fundid, fromFile);
                if (id.HasValue)
                {
                    return(Redirect("/PostBundle/" + id));
                }

                return(RedirectToAction("Batch"));
            }
            catch (Exception ex)
            {
                return(PageMessage(ViewExtensions2.Markdown(ex.Message).ToString()));
            }
        }
예제 #2
0
        public ActionResult BatchUpload(DateTime date, HttpPostedFileBase file, int?fundid, string text)
        {
            var    fromFile = false;
            string s;

            if (file != null)
            {
                var buffer = new byte[file.ContentLength];
                file.InputStream.Read(buffer, 0, file.ContentLength);
                System.Text.Encoding enc;
                if (buffer[0] == 0xFF && buffer[1] == 0xFE)
                {
                    enc = new System.Text.UnicodeEncoding();
                    s   = enc.GetString(buffer, 2, buffer.Length - 2);
                }
                else
                {
                    enc = new System.Text.ASCIIEncoding();
                    s   = enc.GetString(buffer);
                }

                fromFile = true;
            }
            else
            {
                s = text;
            }

            try
            {
                var id = BatchImportContributions.BatchProcess(s, date, fundid, fromFile);
                if (id.HasValue)
                {
                    return(Redirect("/PostBundle/" + id));
                }
                return(RedirectToAction("Batch"));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }