public void BooleanExpressionComplexSerializeTest() { ItemFilter filter1 = new CategoryFilter("cat"); IBooleanExpression leaf1 = new MaxAmount(10, filter1); ItemFilter filter2 = new AllProductsFilter(); IBooleanExpression leaf2 = new UserCountry("Wakanda forever", filter2); IBooleanExpression complex = new XorExpression(); leaf1.id = 1; leaf2.id = 2; complex.addChildren(leaf1, leaf2); string json = JsonConvert.SerializeObject(complex, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); IBooleanExpression result = JsonConvert.DeserializeObject <IBooleanExpression>(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }); Assert.IsInstanceOfType(result, typeof(XorExpression)); Assert.IsInstanceOfType(((XorExpression)result).firstChild, typeof(MaxAmount)); Assert.IsInstanceOfType(((XorExpression)result).secondChild, typeof(UserCountry)); }
public void DiscountSerializeTest() { ItemFilter filter1 = new CategoryFilter("cat"); IBooleanExpression leaf1 = new MaxAmount(10, filter1); ItemFilter filter2 = new AllProductsFilter(); IBooleanExpression leaf2 = new UserCountry("Wakanda forever", filter2); IBooleanExpression complex = new XorExpression(); //we add manually ids for the leaves becuase there is no stub for them at the moment. //Not adding these ids will cause the json serializer to falsly think it has a loop (parent and children have the same id -> .Equals() = true) leaf2.id = 10; leaf1.id = 11; complex.addChildren(leaf1, leaf2); //TODO: when there are concrete Outcomes, we can test this //IOutcome outcome = new //Discount discount = new Discount(complex,) string json = JsonConvert.SerializeObject(complex, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); IBooleanExpression result = JsonConvert.DeserializeObject <IBooleanExpression>(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }); Assert.IsInstanceOfType(result, typeof(XorExpression)); Assert.IsInstanceOfType(((XorExpression)result).firstChild, typeof(MaxAmount)); Assert.IsInstanceOfType(((XorExpression)result).secondChild, typeof(UserCountry)); }
private void SaveUserDependants(User daoObj) { for (int i = 0; i < daoObj.UserCountryList.Count; i++) { UserCountry country = (UserCountry)daoObj.UserCountryList[i]; country.User = daoObj; // HibernateTemplate.Save() returns just ID. real new entity lies in the same daoObj after return. //daoObj.UserCountryList[i] = HibernateTemplate.Save(country); HibernateTemplate.Save(country); daoObj.UserCountryList[i] = country; } for (int i = 0; i < daoObj.UserRegionList.Count; i++) { UserRegion r = (UserRegion)daoObj.UserRegionList[i]; r.User = daoObj; // HibernateTemplate.Save() returns just ID. real new entity lies in the same daoObj after return. //daoObj.UserRegionList[i] = HibernateTemplate.Save(r); HibernateTemplate.Save(r); daoObj.UserRegionList[i] = r; } for (int i = 0; i < daoObj.UserStoreList.Count; i++) { UserStore s = (UserStore)daoObj.UserStoreList[i]; s.User = daoObj; // HibernateTemplate.Save() returns just ID. real new entity lies in the same daoObj after return. //daoObj.UserStoreList[i] = HibernateTemplate.Save(s); HibernateTemplate.Save(s); daoObj.UserStoreList[i] = s; } }
public ActionResult CreateUser(User user, List <int> Country) { if (user != null) { if (Current.Context.User.Where(d => d.Email == user.Email).Count() > 0) { TempData["ErrorType"] = "Fail"; TempData["Message"] = "Bu eposta adresine ait kullanıcı mevcuttur!"; return(View("Index")); } if (user.Email == null) { TempData["ErrorType"] = "Fail"; TempData["Message"] = "Eposta adresi boş geçilemez!"; return(View("Index")); } User newUser = new User(); newUser.Email = user.Email; newUser.Password = Utilities.ConvertToMD5(user.Password); newUser.Name = user.Name; newUser.UserTypeId = user.UserTypeId; newUser.Surname = user.Surname; newUser.Status = true; Current.Context.User.Add(newUser); Current.Context.SaveChanges(); if (Country != null && Country.Count() > 0) { foreach (var item in Country) { if (item != -1) { UserCountry newUserCountry = new UserCountry { UserId = newUser.Id, CountryId = item }; Current.Context.UserCountry.Add(newUserCountry); Current.Context.SaveChanges(); } } } TempData["ErrorType"] = "Success"; TempData["Message"] = "Kullanıcı ekleme işlemi başarı ile sonuçlanmıştır!"; } else { TempData["ErrorType"] = "Fail"; TempData["Message"] = "İşlem başarısız olmuştur!"; } return(View("Index")); }
public void UserCountryevaluateTest() { UserCountry country = new UserCountry("A", filter); Assert.IsFalse(country.evaluate(list, user)); country = new UserCountry("B", filter); Assert.IsTrue(country.evaluate(list, user)); }
public void AddUserCountry(string countryName, string countryId, User user) { if (countryId == null) { countryId = GetCountry(linqWhereCountry: x => x.Name == countryName).ID; } var userCountry = new UserCountry { UserCountryID = Guid.NewGuid().ToString(), UserID = user.ID, CountryID = countryId }; _context.UserCountries.Add(userCountry); }
protected string GetTotal(UserCountry country) { try { var client = Connector.GetHttpClient(); HttpResponseMessage result = client.GetAsync("Dashboard/CountTicketsByCountry?country=" + country).Result; var content = result.Content.ReadAsStringAsync().Result; return(content); } catch (Exception ex) { GlobalVariable.log.Write(LogLevel.Error, ex); return(null); } }
//Number of tickets from users per country public int GetTicketsByUserCountryCount(UserCountry country) { try { return((from u in db.Users join t in db.Tickets on u.Id equals t.ClientId where u.Type == UserType.Client && u.Country == country select t).Count()); } catch (Exception ex) { GlobalVariable.log.Write(LogLevel.Error, ex); return(0); } }
public User(int userID, string firstName, string lastName, string userName, UserRole role, DateTime birthdayDate, UserCountry country, UserGender gender, string email, string password, bool isDeleted, Int32 pictureID) { ID = userID; FirstName = firstName; LastName = lastName; Role = role; Country = country; Gender = gender; Email = email; Password = password; BirthdayDate = birthdayDate; UserName = userName; IsDeleted = isDeleted; PictureID = pictureID; }
private void CommitCountries() { if (_CountriesModified) { List <Domain.Country> removed = _CountryBindList.GetRemoveList(); foreach (Domain.Country rc in removed) { IList ucs = UserEntity.UserCountryList; foreach (UserCountry uc in ucs) { if (uc.CountryID == rc.ID) { ucs.Remove(uc); break; } } } List <Domain.Country> newc = _CountryBindList.GetNewItemList(); foreach (Domain.Country nc in newc) { bool found = false; IList ucs = UserEntity.UserCountryList; for (int i = 0; i < ucs.Count; i++) { UserCountry uc = (UserCountry)ucs[i]; if (uc.CountryID == nc.ID) { found = true; break; } } if (!found) { UserCountry uc = new UserCountry(); uc.User = UserEntity; uc.CountryID = nc.ID; UserEntity.UserCountryList.Add(uc); } } } }
public ActionResult EditUser(User user, List <int> Country) { if (user != null && user.Id != -1) { User usr = Current.Context.User.FirstOrDefault(d => d.Id == user.Id); if (usr != null) { usr.Name = user.Name; usr.Surname = user.Surname; usr.GSM = user.GSM; usr.UserTypeId = user.UserTypeId; } Current.Context.SaveChanges(); List <UserCountry> oldCountryList = Current.Context.UserCountry.Where(d => d.UserId == user.Id).ToList(); Current.Context.UserCountry.RemoveRange(oldCountryList); if (Country.Count() > 0) { foreach (var item in Country) { if (item != -1) { UserCountry newUserCountry = new UserCountry { UserId = user.Id, CountryId = item }; Current.Context.UserCountry.Add(newUserCountry); Current.Context.SaveChanges(); } } } TempData["ErrorType"] = "Success"; TempData["Message"] = "Kullanıcı güncelleme işlemi başarı ile sonuçlanmıştır!"; } else { TempData["ErrorType"] = "Fail"; TempData["Message"] = "İşlem başarısız olmuştur!"; } return(View("Index")); }
public async Task <ActionResult> Create(FormCreateViewModel model) { User user = new User(); user.ID = model.FirstName + new Random().Next(999999999).ToString() + model.LastName; user.FirstName = model.FirstName; user.LastName = model.LastName; user.Email = model.Email; user.Gender = model.Gender; context.Users.Add(user); var countryId = context.Countries.Where(m => m.Name == model.Country).Select(m => m.ID).FirstOrDefault(); UserCountry userCountry = new UserCountry(); userCountry.UserID = user.ID; userCountry.CountryID = countryId; context.UserCountries.Add(userCountry); UserDescription userDescription = new UserDescription(); userDescription.ID = user.ID + countryId; userDescription.UserID = user.ID; userDescription.Description = model.Description; context.UserDescriptions.Add(userDescription); foreach (var course in model.Courses) { UserCourse userCourse = new UserCourse(); if (course.Checked == true) { userCourse.UserID = user.ID; userCourse.CourseID = course.ID; userCourse.Checked = true; context.UserCourses.Add(userCourse); } } await context.SaveChangesAsync(); return(RedirectToAction("Index", "FormExample")); }
public HttpResponseMessage CountTicketsByCountry(UserCountry country) { try { var response = manager.GetTicketsByUserCountryCount(country); if (response > 0) { return(Request.CreateResponse(HttpStatusCode.OK, response)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, 0)); } } catch (Exception ex) { GlobalVariable.log.Write(LogLevel.Error, ex); return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public ActionResult Edit(FormCreateViewModel model) { User user = context.Users.Where(u => u.ID == model.UserID).FirstOrDefault(); TryUpdateModel(user, "", new string[] { "FirstName", "LastName", "Email", "Gender" }); UserDescription userDescription = context.UserDescriptions.Where(u => u.UserID == model.UserID).FirstOrDefault(); TryUpdateModel(userDescription, "", new string[] { "Description" }); UserCountry userCountry = context.UserCountries.Where(u => u.UserID == model.UserID).FirstOrDefault(); var countryId = context.Countries.Where(n => n.Name == model.Country).Select(i => i.ID).FirstOrDefault(); if (userCountry.CountryID != countryId) { if (userCountry != null) { context.UserCountries.Remove(userCountry); context.SaveChanges(); } UserCountry uCountry = new UserCountry(); uCountry.UserID = model.UserID; uCountry.CountryID = countryId; context.UserCountries.Add(uCountry); } var userCourses = context.UserCourses.Where(u => u.UserID == model.UserID).ToList(); List <string> uCourseIds = new List <string>(); foreach (var crId in userCourses) { uCourseIds.Add(crId.CourseID); } var newCourses = model.Courses.Where(x => x.Checked == true).ToList(); List <string> nCourseIds = new List <string>(); foreach (var crId in newCourses) { nCourseIds.Add(crId.ID); } if (!uCourseIds.SequenceEqual(nCourseIds)) { foreach (var crId in userCourses) { UserCourse userCourse = context.UserCourses.Where(x => x.UserID == model.UserID && x.CourseID == crId.CourseID).FirstOrDefault(); context.UserCourses.Remove(userCourse); context.SaveChanges(); } foreach (var course in model.Courses) { UserCourse userCourse = new UserCourse(); if (course.Checked == true) { userCourse.UserID = user.ID; userCourse.CourseID = course.ID; userCourse.Checked = true; context.UserCourses.Add(userCourse); } } } context.SaveChanges(); return(RedirectToAction("Index", "FormExample")); }
public void RemoveUserCountry(UserCountry userCountry) { _context.UserCountries.Remove(userCountry); }