public ActionResult Recall()
        {
            RecallLinesModel         = new RecallLinesViewModel();
            RecallLinesModel.Recalls = new List <RecallLineViewModel>();

            var recallLinesModel = (RecallLinesViewModel)ViewData["recalls"];

            if (recallLinesModel != null)
            {
                RecallLinesModel = recallLinesModel;
            }
            return(View(RecallLinesModel));
        }
        public ActionResult ImportRecalls(HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var allowedExtensions = new[] { ".xlsx", ".csv" };
                    if (upload.FileName.EndsWith(".csv"))
                    {
                        Stream       stream    = upload.InputStream;
                        StreamReader csvreader = new StreamReader(stream);
                        csvreader.ReadLine(); // skip the headers : first line

                        RecallLinesModel         = new RecallLinesViewModel();
                        RecallLinesModel.Recalls = new List <RecallLineViewModel>();

                        while (!csvreader.EndOfStream)
                        {
                            var line   = csvreader.ReadLine();
                            var values = line.Split(',');

                            string PatientName  = values[0];
                            string MedicineName = values[1];

                            // create recall lines
                            var RecallLineModel = new RecallLineViewModel {
                                IsSelected = true, PatientName = PatientName, MedicineName = MedicineName
                            };
                            RecallLinesModel.Recalls.Add(RecallLineModel);
                        }
                    }
                    else if (upload.FileName.EndsWith(".xlsx"))
                    {
                        TempData["CustomError"] = "This is a .xlsx file!";
                    }
                    else
                    {
                        TempData["CustomError"] = "The file has to be a .csv file!";
                    }
                }
                else
                {
                    TempData["CustomError"] = "You need to upload a file!";
                }
            }

            return(View(RecallLinesModel.Recalls));
        }