public ActionResult Register(AccountVM.RegisterViewModel user) { if (ModelState.IsValid) { UserDTO userDTO = new UserDTO(); userDTO = _mapper.Map <AccountVM.RegisterViewModel, UserDTO>(user); userDTO.Password = HashFunction.CreateHash(userDTO.Password); int?loggedIn = ConvertString.ConvertToInt(_iapiResponse.Post <UserDTO>("users", userDTO)); if (loggedIn == (int)StatusCode.ISEXISTSUSER) { ModelState.AddModelError("Email", "Email is alredy exists"); return(View(user)); } else if (loggedIn != null) { FormsAuthentication.SetAuthCookie(user.Email, false); bool login = _iapiResponse.Authentication(userDTO); return(RedirectToAction("Index", "Home")); } } ModelState.AddModelError("", "Can't register your account"); return(View(user)); }
public void ConvertStringConstructorTest1() { CharacterStringTypes dataType = new CharacterStringTypes(); // TODO: Initialize to an appropriate value Expression expression = null; // TODO: Initialize to an appropriate value ConvertString target = new ConvertString(dataType, expression); Assert.Inconclusive("TODO: Implement code to verify target"); }
public bool UpdateUserPassword(string id, string newPassword) { if (CheckUserNewPassword(id, newPassword)) { int mod4 = id.Length % 4; if (mod4 > 0) { id += new string('=', 4 - mod4); } var userId = Convert.ToInt32(ConvertString.MD5Decode(id)); var currentClient = _context.Users.Find(userId); if (currentClient.Id == userId) { currentClient.Password = newPassword; _context.SaveChanges(); _notificationsService.SendPasswordChangeNotification(currentClient); return(true); } else { return(false); } } else { return(false); } }
public ActionResult Edit(AccountVM.EditUserViewModel user, HttpPostedFileBase file) { if (ModelState.IsValid) { UserDTO userDTO = new UserDTO(); userDTO.Email = User.Identity.GetUserName(); userDTO.DisplayName = user.DisplayName; if (file == null) { if (ConvertString.ConvertToBool(_iapiResponse.Put <UserDTO>("users", userDTO))) { return(RedirectToAction("Index", "Home")); } } else if (file != null && ImageFunction.IsImage(file.InputStream)) { Image resizeImage = ImageFunction.ScaleImage(Image.FromStream(file.InputStream), 200, 200); userDTO.ImageUser = ImageFunction.imageToByteArray(resizeImage); if (ConvertString.ConvertToBool(_iapiResponse.Put <UserDTO>("users", userDTO))) { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Image is not correct file format"); return(View(user)); } } return(View(user)); }
//admin create new public void AdminCreateMusic(MusicDTO music) { //Save the Byte Array as File. try { var data = new MusicDao().Create(new Music() { MusicDayCreate = DateTime.Now, MusicName = music.MusicName, MusicDownloadAllowed = true, SongOrMV = music.SongOrMV, CategoryId = music.CategoryId, MusicImage = music.MusicImage, MusicNameUnsigned = ConvertString.convertToUnSign2(music.MusicName), MusicView = 0, UserID = music.UserID, MusicRelated = music.MusicRelated }); } catch (Exception e) { Console.WriteLine(e); throw; } }
//update music public bool AdminUpdateMusic(MusicDTO music) { var data = new Music() { ID = music.ID, MusicDayCreate = DateTime.Now, MusicName = music.MusicName, MusicDownloadAllowed = music.MusicDownloadAllowed, SongOrMV = music.SongOrMV, UserID = music.UserID, CategoryId = music.CategoryId, MusicImage = music.MusicImage, MusicRelated = music.MusicRelated, MusicNameUnsigned = ConvertString.convertToUnSign2(music.MusicName), }; try { new MusicDao().Update(data); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }
public void ConvertToIntTest_CorrectInputIntMin() { var converter = new ConvertString(); var result = converter.ConvertToInt(int.MinValue.ToString()); Assert.AreEqual(int.MinValue, result); }
public ActionResult Create([Bind(Prefix = "post")] PostVM.PostCreateVM post, HttpPostedFileBase file) { if (ModelState.IsValid) { post.Email = User.Identity.GetUserName(); PostDTO postDTO = new PostDTO(); postDTO = _imapper.Map <PostVM.PostCreateVM, PostDTO>(post); if (file == null) { if (ConvertString.ConvertToBool(_iapiResponse.Post <PostDTO>("posts", postDTO))) { return(RedirectToAction("Index", "Home")); } } else if (file != null && ImageFunction.IsImage(file.InputStream)) { Image resizeImage = ImageFunction.ScaleImage(Image.FromStream(file.InputStream), (int)StatusCode.MAX_WIDTH, (int)StatusCode.MAX_HEIGHT); postDTO.Image = ImageFunction.imageToByteArray(resizeImage); if (ConvertString.ConvertToBool(_iapiResponse.Post <PostDTO>("posts", postDTO))) { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Image is not correct file format"); return(View(post)); } } ModelState.AddModelError("", "Can't upload your post"); return(View(post)); }
public void ConvertToIntTest_CorrectInput() { var converter = new ConvertString(); var result = converter.ConvertToInt("500"); Assert.AreEqual(500, result); }
public int EditItem(int id, POST Post) { POST PostEdit = db.POSTs.Find(id); using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { PostEdit.TITLE = Post.TITLE; PostEdit.URL_SLUG = ConvertString.ToUrlSlug(Post.TITLE); PostEdit.DATE_EDIT = DateTime.Now; PostEdit.ACTIVE = Post.ACTIVE; PostEdit.DESCRIPTION = Post.DESCRIPTION; PostEdit.DETAIL = Post.DETAIL; PostEdit.PICTURE = Post.PICTURE; db.Entry(PostEdit).State = EntityState.Modified; int i = db.SaveChanges(); transaction.Commit(); return(Post.ID); } catch { transaction.Rollback(); return(0); } } }
static void Main(string[] args) { StudentData sd = new StudentData(); // List<Student> students = sd.GetFilteredStudents(); List <Student> students = sd.GetAllStudents(); List <String> fruits = new List <string> { "appel", "pear", "banana", "strawberry", "lemon" }; foreach (string fruit in fruits) { // Console.WriteLine(fruit.ToUpper()); ConvertString toCaps = x => x.ToUpper(); CountString countString = x => x.Count(); Console.WriteLine(toCaps(fruit) + " telt " + countString(fruit) + " tekens"); // Console.WriteLine(fruit + " telt " + fruit.Count() + " tekens"); } Console.WriteLine(); for (int i = 0; i < fruits.Count() - 1; i++) { CheckString checkString = (x, y) => x.Count() > y.Count(); Console.WriteLine(fruits[i] + " contains more characters then " + fruits[i + 1] + ": " + checkString(fruits[i], fruits[i + 1])); } Console.WriteLine(); foreach (Student student in students) { CheckAge checkAge = (x, y) => x.Age >= y; Console.WriteLine(student.FirstName + " " + student.LastName + " is " + (checkAge(student, 21) ? "" : "not ") + "old enough."); } Console.ReadKey(); }
public ActionResult Create(Categories categories) { if (ModelState.IsValid) { var sess = (UserLogin)Session[CommonConstant.USER_SESSION]; categories.CreatedBy = sess.Username; categories.CreatedDate = DateTime.Now; categories.ModifiedBy = sess.Username; categories.ModifiedDate = DateTime.Now; categories.SeoUrl = ConvertString.UTF8Convert(categories.Name); long id = access.CreateCategory(categories); if (id > 0) { return(RedirectToAction("Index", "Category")); } else if (id == 0) { ModelState.AddModelError("", "Danh mục đã tồn tại"); } else { ModelState.AddModelError("", "Thêm danh mục thất bại"); } } return(View("Create")); }
public override DownloadInfo Parse(string line, string id = null, Uri source = null, string file = null) { var data = new DownloadInfo(id, file, source); if (string.IsNullOrEmpty(line)) { return(data); } if (_skippedLines < _linesToSkip) { _skippedLines++; return(null); } var items = line.Split(" ", 7, StringSplitOptions.RemoveEmptyEntries); if (items.Length < 7) { return(data); } data.Id = id; data.BytesTotal = ConvertString.ToByteSize(items[1]); data.BytesReceived = ConvertString.ToByteSize(items[3]); data.BytesTransfered = ConvertString.ToByteSize(items[5]); Logger.Debug($"BytesTotal: {data.BytesTotal}"); Logger.Debug($"BytesRecieved: {data.BytesReceived}"); return(data); }
protected override Perfil ConvertDtoToEntity(UserGroupDto dto) { return(new Perfil { Id = dto.Id, Nome = ConvertString.ToPascalCase(dto.Name) }); }
public void ConvertToDateTimeTest() { string strValue = string.Empty; // TODO: 初始化为适当的值 DateTime expected = new DateTime(); // TODO: 初始化为适当的值 DateTime actual; actual = ConvertString.ConvertToDateTime(strValue); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
public void ConvertToDoubleTest() { string strValue = string.Empty; // TODO: 初始化为适当的值 double expected = 0F; // TODO: 初始化为适当的值 double actual; actual = ConvertString.ConvertToDouble(strValue); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
public void ConvertToInt32Test() { string strValue = string.Empty; // TODO: 初始化为适当的值 int expected = 0; // TODO: 初始化为适当的值 int actual; actual = ConvertString.ConvertToInt32(strValue); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
public void ConvertToIPAddressTest() { string strValue = string.Empty; // TODO: 初始化为适当的值 IPAddress expected = null; // TODO: 初始化为适当的值 IPAddress actual; actual = ConvertString.ConvertToIPAddress(strValue); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
public void ConvertToBooleanTest() { string strValue = string.Empty; // TODO: 初始化为适当的值 bool expected = false; // TODO: 初始化为适当的值 bool actual; actual = ConvertString.ConvertToBoolean(strValue); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
public void ToTimeSpanTest() { string strValue = string.Empty; // TODO: 初始化为适当的值 TimeSpan expected = new TimeSpan(); // TODO: 初始化为适当的值 TimeSpan actual; actual = ConvertString.ToTimeSpan(strValue); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
public void ToByteArrayTest1() { string byteString = string.Empty; // TODO: 初始化为适当的值 byte[] expected = null; // TODO: 初始化为适当的值 byte[] actual; actual = ConvertString.ToByteArray(byteString); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
public void ToLong64Test() { string strValue = string.Empty; // TODO: 初始化为适当的值 long expected = 0; // TODO: 初始化为适当的值 long actual; actual = ConvertString.ToLong64(strValue); Assert.AreEqual(expected, actual); Assert.Inconclusive("验证此测试方法的正确性。"); }
protected override Area ConvertDtoToEntity(AreaDto dto) { return(new Area { Id = dto.Id, Parent = this.entities.FirstOrDefault(x => x.Id == dto.Parent.ToInt()), Nome = ConvertString.ToPascalCase(dto.Descricao), Segura = dto.Restricted == "S", Abreviacao = ConvertString.ToPascalCase(dto.Abrev) }); }
protected override TipoDocumento ConvertDtoToEntity(GroupDocDto dto) { return(new TipoDocumento { Id = dto.Id, Nome = string.IsNullOrEmpty(dto.Descricao) ? "(vazio)" : ConvertString.ToPascalCase(dto.Descricao), Ativo = dto.Active == "S", Parent = this.entities.FirstOrDefault(x => x.Id == dto.Parent.ToInt()), EhPasta = dto.Folder == "G", }); }
public void CoalitionTest() { string strString = string.Empty; // TODO: 初始化为适当的值 StringBuilder stringBuilder = null; // TODO: 初始化为适当的值 StringBuilder stringBuilderExpected = null; // TODO: 初始化为适当的值 string strString2 = string.Empty; // TODO: 初始化为适当的值 ConvertString.Coalition(strString, ref stringBuilder, strString2); Assert.AreEqual(stringBuilderExpected, stringBuilder); Assert.Inconclusive("无法验证不返回值的方法。"); }
public void convertStringTest() { var c = new ConvertString(); Assert.IsTrue(c.convertString("ceoydefthf5iyg5h5yts", "codefights")); Assert.IsFalse(c.convertString("addbyca", "abcd")); Assert.IsTrue(c.convertString("abc", "abc")); Assert.IsFalse(c.convertString("a", "abc")); Assert.IsTrue(c.convertString("gooddaywithcoffee17righteh", "gowithcoffe1e")); Assert.IsTrue(c.convertString("aaaAaaaAbbBbcCcc", "aBc")); Assert.IsFalse(c.convertString("spjrtytmeed", "spotme")); }
protected override Usuario ConvertDtoToEntity(UserDto dto) { return(new Usuario { Id = dto.Id, Login = ConvertString.ToPascalCase(dto.Login), Nome = dto.Name, Ativo = dto.Active == "S" && dto.Deleted != "*", Perfil = this.Create <Perfil>(dto.Profile), Area = this.Create <Area>(dto.Area), Senha = new HashString().Do("pwd123") }); }
public void OpenSingleton() { var assetMap = UnitAssets.Map; var map = this.map = new SortedDictionary <long, Unit>(new CodeComparer()); var ordered = this.ordered = new List <Unit>(assetMap.Count); foreach (var asset in assetMap.Values) { if (!this.VerifyModel(asset)) { continue; } var unit = new Unit(asset); map.Add(unit.Code, unit); } ordered.Sort((x, y) => { var orderX = x.Order; var orderY = y.Order; if (orderX < orderY) { return(-1); } else if (orderX > orderY) { return(+1); } var codeX = x.Code; var codeY = y.Code; if (codeX < codeY) { return(-1); } else if (codeX > codeY) { return(+1); } return(0); }); #if LOG_DATA Debug.Log(string.Format("UNITSKILL:{0}", ConvertString.Execute(map))); Debug.Log(string.Format("UNITSKILL:ORDERED:{0}", ConvertString.Execute(ordered))); #endif// LOG_DATA }
public ActionResult Update(Categories categories) { if (ModelState.IsValid) { var sess = (UserLogin)Session[CommonConstant.USER_SESSION]; categories.ModifiedBy = sess.Username; categories.SeoUrl = ConvertString.UTF8Convert(categories.Name); bool result = access.UpdateCategory(categories); if (result) { return(RedirectToAction("Index", "Category")); } else { ModelState.AddModelError("", "Cập nhật danh mục thất bại"); } } return(View("Update")); }
public override DownloadInfo Parse(string line, string id = null, Uri source = null, string file = null) { var data = new DownloadInfo(id, file, source); if (string.IsNullOrEmpty(line) || !line.Contains("%")) { return(data); } Logger.Debug("Downloader Line: " + line); var items = line.Split(" ", 7, StringSplitOptions.RemoveEmptyEntries); if (items.Length < 7) { return(data); } data.Id = id; if (items[2] == "of") { data.BytesTotal = ConvertString.ToByteSize(items[3]); } else { data.BytesTotal = ConvertString.ToByteSize(items[2]); } var percentStr = items[1].Replace("%", ""); if (percentStr != null && data.BytesTotal > 0) { var percent = float.Parse(percentStr, NumberStyles.Number, new CultureInfo("en-US")); if (percent > 0) { data.BytesReceived = (int)((data.BytesTotal * percent) / 100); } else { data.BytesReceived = 0; } } Logger.Debug($"BytesTotal: {data.BytesTotal}"); Logger.Debug($"BytesRecieved: {data.BytesReceived}"); return(data); }
public int AddItem(CATEGORy Category) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { Category.URL_SLUG = ConvertString.ToUrlSlug(Category.NAME); db.CATEGORIES.Add(Category); int i = db.SaveChanges(); transaction.Commit(); return(Category.ID); } catch { transaction.Rollback(); return(0); } } }