public ActionResult AddFromFile(UsersFromFile usersFile) { if (ModelState.IsValid) { byte[] array; string csv = string.Empty; using (MemoryStream ms = new MemoryStream()) { usersFile.File.InputStream.CopyTo(ms); array = ms.ToArray(); } switch (usersFile.EncodeType) { case EncodeType.UTF8: csv = Encoding.UTF8.GetString(array); break; case EncodeType.UTF32: csv = Encoding.UTF32.GetString(array); break; case EncodeType.ASCII: csv = Encoding.ASCII.GetString(array); break; } var userParser = new UsersParser(csv); var usersEM = userParser.ParseUsers(); if (userParser.Errors.Count() == 0) { var users = Mapper.Map <IEnumerable <UserEditModel>, IEnumerable <ApplicationUser> >(usersEM); _userRepository.AddRange(users); this.AddStatus(StatusType.SUCCESS, "Пользователи успешно добавлены!"); return(RedirectToAction("Index")); } } return(View(usersFile)); }
public ActionResult AddFromFile() { var model = new UsersFromFile(); return(View(model)); }