Exemplo n.º 1
0
        public string MakeEmployeeSCV()
        {
            List <MainUser> users = _empRepo.GetAllUser();

            using (var memoryStream = new MemoryStream())
                using (var streamWriter = new StreamWriter(memoryStream))
                    using (var csv = new CsvWriter(streamWriter))
                    {
                        csv.WriteRecords(users);
                        streamWriter.Flush();

                        memoryStream.Position = 0;
                        using (var reader = new StreamReader(memoryStream))
                        {
                            return(reader.ReadToEnd());
                        }
                    }
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var mvcName = typeof(Controller).Assembly.GetName();
            var isMono  = Type.GetType("Mono.Runtime") != null;

            ViewData["Version"] = mvcName.Version.Major + "." + mvcName.Version.Minor;
            ViewData["Runtime"] = isMono ? "Mono" : ".NET";

            try
            {
                _empRepo.GetAllUser();
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }

            return(View());
        }
Exemplo n.º 3
0
        public string MakeCSV()
        {
            StringBuilder csv = new StringBuilder();

            csv.Append(MakeCSVColumn() + Environment.NewLine);

            List <MainUser> allUser = _empRepo.GetAllUser();

            foreach (var u in allUser)
            {
                string row = string.Empty;
                row = row + u.Id + ", ";
                row = row + u.UserName + ", ";
                row = row + u.UserType.ToString() + ", ";
                row = row + u.IsActive + ", ";
                row = row + u.Islock + ", ";

                if (u.Details != null)
                {
                    row = row + '"' + u.Details.LastName + '"' + ", ";
                    row = row + '"' + u.Details.FirstName + '"' + ", ";
                    row = row + '"' + u.Details.Language + '"' + ", ";
                    row = row + u.Details.BirthDate.ToString() + ", ";
                    row = row + u.Details.Age + ", ";
                    row = row + '"' + u.Details.HobbiesAndInterest + '"' + ", ";
                    row = row + u.Details.CivilStatus.ToString() + ", ";
                    row = row + u.Details.Gender.ToString() + ", ";
                    row = row + u.Details.PhoneNumber + ", ";
                    row = row + '"' + u.Details.Address + '"' + ", ";
                    row = row + '"' + u.Details.Country + '"' + ", ";
                    row = row + '"' + u.Details.State + '"';
                }
                row = row + Environment.NewLine;
                csv.Append(row);
            }

            return(csv.ToString());
        }