public async Task <Unit> Handle(UpdateCategoryDBCommand request, CancellationToken cancellationToken) { var category = await context.Categories.FindAsync(request.Category.Id); category.Name = request.Category.Name; category.Description = request.Category.Description; foreach (var attr in request.Category.Attributes) { var dbAttr = category.Attributes.FirstOrDefault(x => x.Id == attr.Id); if (dbAttr == null) { dbAttr = new Entities.Attribute() { Id = attr.Id, Category = category }; context.Attributes.Add(dbAttr); } dbAttr.Type = attr.Type; dbAttr.Name = attr.Name; } await context.SaveChangesAsync(); return(new Unit()); }
public async Task <IHttpActionResult> PutCategoryAttribute(Guid id, CategoryAttribute categoryAttribute) { Entities.Attribute attribute = await db.Attributes.FirstOrDefaultAsync(x => x.Value == categoryAttribute.Target.Value && x.Code == categoryAttribute.Target.Code); if (attribute == null) { categoryAttribute.Target.Id = Guid.NewGuid(); categoryAttribute.TargetId = categoryAttribute.Target.Id; db.Attributes.Add(categoryAttribute.Target); await db.SaveChangesAsync(); attribute = await db.Attributes.FindAsync(categoryAttribute.TargetId); } else { db.Entry(attribute).CurrentValues.SetValues(categoryAttribute.Target); await db.SaveChangesAsync(); } CategoryAttribute existedCategoryAttribute = await db.CategoryAttributes.FindAsync(id); db.Entry(existedCategoryAttribute).CurrentValues.SetValues(categoryAttribute); await db.SaveChangesAsync(); return(Ok(existedCategoryAttribute)); }
public async Task <ActionResult> DeleteConfirmed(int id) { Entities.Attribute attribute = await db.Attributes.FindAsync(id); db.Attributes.Remove(attribute); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
private Participant CreateParticipant(Calendar calendar, User user, string displayName, string firstName, string lastName, string email, Gender gender, string mobile, string phone, string address, string attributes) { if (calendar == null) { throw new ArgumentNullException(nameof(calendar)); } if (user == null) { throw new ArgumentNullException(nameof(user)); } Address home = null; if (!String.IsNullOrWhiteSpace(address)) { var parts = address.Split(',').Select(v => v.Trim()).ToArray(); home = new Address("Home", parts[0], parts[1], parts[2], parts[3], parts[4]); } var p = new Participant(calendar, displayName, firstName, lastName, email, home) { AddedById = user.Id, Gender = gender }; this.Context.Participants.Add(p); if (!String.IsNullOrWhiteSpace(mobile)) { var ci = new ContactInfo(p, "Mobile", ContactInfoType.Mobile, ContactInfoCategory.Personal, mobile) { AddedById = user.Id }; this.Context.ContactInfo.Add(ci); } if (!String.IsNullOrWhiteSpace(mobile)) { var ci = new ContactInfo(p, "Home Phone", ContactInfoType.Phone, ContactInfoCategory.Personal, phone) { AddedById = user.Id }; this.Context.ContactInfo.Add(ci); } if (!String.IsNullOrWhiteSpace(attributes)) { var parts = attributes.Split(',').Select(v => v.Trim()).ToArray(); foreach (var part in parts) { var kv = part.Split('='); var a = new Entities.Attribute(p, kv[0], kv[1], kv[1].Equals("true") ? typeof(bool) : typeof(string)) { AddedById = user.Id }; this.Context.Attributes.Add(a); } } return(p); }
public async Task <IHttpActionResult> PostAttribute(Entities.Attribute attribute) { db.Attributes.Add(attribute); await db.SaveChangesAsync(); await db.Entry(attribute).GetDatabaseValuesAsync(); return(Ok(attribute)); }
public async Task <IHttpActionResult> PutAttribute(Guid id, Entities.Attribute attribute) { Entities.Attribute existedAttribute = await db.Attributes.FindAsync(id); db.Entry(existedAttribute).CurrentValues.SetValues(attribute); await db.Entry(existedAttribute).GetDatabaseValuesAsync(); return(Ok(existedAttribute)); }
public async Task <IHttpActionResult> GetAttribute(Guid id) { Entities.Attribute existedAttribute = await db.Attributes.FindAsync(id); if (existedAttribute == null) { return(NotFound()); } return(Ok(existedAttribute)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name")] Entities.Attribute attribute) { if (ModelState.IsValid) { db.Entry(attribute).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.Id = new SelectList(db.AttributeTypes, "Id", "Type", attribute.Id); return(View(attribute)); }
public async Task <IHttpActionResult> DeleteAttribute(Guid id) { Entities.Attribute existedAttribute = await db.Attributes.FindAsync(id); if (existedAttribute == null) { return(NotFound()); } db.Attributes.Remove(existedAttribute); await db.SaveChangesAsync(); return(Ok()); }
// GET: Attributes/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Entities.Attribute attribute = await db.Attributes.FindAsync(id); if (attribute == null) { return(HttpNotFound()); } return(View(attribute)); }
// GET: Attributes/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Entities.Attribute attribute = await db.Attributes.FindAsync(id); if (attribute == null) { return(HttpNotFound()); } ViewBag.Id = new SelectList(db.AttributeTypes, "Id", "Type", attribute.Id); return(View(attribute)); }
public async Task <IHttpActionResult> PostCategoryAttribute(CategoryAttribute categoryAttribute) { Entities.Attribute attribute = db.Attributes.FirstOrDefault(x => x.Value == categoryAttribute.Target.Value && x.Code == categoryAttribute.Target.Code); if (attribute != null) { categoryAttribute.Target = null; categoryAttribute.TargetId = attribute.Id; } db.CategoryAttributes.Add(categoryAttribute); await db.SaveChangesAsync(); await db.Entry(categoryAttribute).GetDatabaseValuesAsync(); return(Ok(categoryAttribute)); }
public async Task <IHttpActionResult> PutAttributeWithInventory(Guid id, InventoryAttribute inventoryAttribute) { Entities.Attribute attribute = await db.Attributes.FirstOrDefaultAsync(x => x.Value == inventoryAttribute.Target.Value); if (attribute == null) { db.Attributes.Add(inventoryAttribute.Target); await db.SaveChangesAsync(); attribute = await db.Attributes.FindAsync(inventoryAttribute.Target.Id); } inventoryAttribute.TargetId = attribute.Id; InventoryAttribute existedInventoryAttribute = await db.InventoryAttributes.FindAsync(id); db.Entry(existedInventoryAttribute).CurrentValues.SetValues(inventoryAttribute); await db.SaveChangesAsync(); return(Ok(existedInventoryAttribute)); }
public static async void Initialize(IServiceProvider serviceProvider) { Random random = new Random(); const string loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam justo turpis, consequat a orci id, consequat fringilla libero. Curabitur sodales, neque sit amet dapibus dignissim, magna dolor iaculis tellus, et porta quam eros ac sem."; string[] stringRemoves = new string[] { " ", ".", "," }; const int userCount = 5; const int dictionaryCount = 6; const int dictionaryCountRandomRange = 5; const int translationCount = 10; const int translationCountRandomRange = 5; const int attributeCount = 5; const int attributeCountRandomRange = 2; const int attributeValueCount = 3; const int attributeValueCountRandomRange = 2; const int attributeParameterCount = 3; const int attributeParameterCountRandomRange = 1; const int viewerCount = 3; var users = new List <User>(); using (var userManager = serviceProvider.GetRequiredService <UserManager <User> >()) { if (!userManager.Users.Any()) { for (int i = 0; i < userCount; i++) { User user; if (random.Next(3) == 2) { user = new User() { Email = $"admin{i}@admin.xpl", SecurityStamp = Guid.NewGuid().ToString(), UserName = $"Admin{i}" }; await userManager.CreateAsync(user, "123456"); await userManager.AddToRoleAsync(user, "Administrator"); } else { user = new User() { Email = $"user{i}@user.xpl", SecurityStamp = Guid.NewGuid().ToString(), UserName = $"User{i}" }; await userManager.CreateAsync(user, "123456"); await userManager.AddToRoleAsync(user, "User"); } users.Add(user); } } else { users = await userManager.Users.Include(u => u.Attributes).ToListAsync(); } } using (var context = serviceProvider.GetRequiredService <MEMOContext>()) { foreach (var user in users) { var languages = await context.Languages.ToListAsync(); var attributes = new List <Entities.Attribute>(); if (!user.Attributes.Any()) { for (int i = 0; i < attributeCount + (random.Next(2) == 0 ? random.Next(attributeCountRandomRange) : -random.Next(attributeCountRandomRange)); i++) { var idx = random.Next(loremIpsum.Length - 6); AttributeType type; switch (random.Next(3)) { case 0: type = AttributeType.text; break; case 1: type = AttributeType.spinner; break; case 2: type = AttributeType.checkbox; break; default: type = AttributeType.text; break; } var attribute = new Entities.Attribute { Name = type == AttributeType.text ? "példamondat" : type == AttributeType.spinner ? "szófaj" : "fontos", User = user, Type = type }; attributes.Add(attribute); context.Add(attribute); } } else { attributes = await context.Attributes.Where(a => a.UserId == user.Id) .Include(a => a.AttributeParameters) .ToListAsync(); } foreach (var attribute in attributes) { if (attribute.Type == AttributeType.spinner) { if (!attribute.AttributeParameters.Any()) { for (int i = 0; i < attributeParameterCount + (random.Next(2) == 0 ? random.Next(attributeParameterCountRandomRange) : -random.Next(attributeParameterCountRandomRange)); i++) { var idx = random.Next(loremIpsum.Length - 6); var attributeParameter = new AttributeParameter { Value = loremIpsum.CustomSubstring(idx, 6, stringRemoves), Attribute = attribute }; context.Add(attributeParameter); } } } } var dictionaries = new List <Dictionary>(); if (!context.UserDictionaries.Where(ud => ud.UserId == user.Id && ud.Type == UserType.owner) .Any()) { for (int i = 0; i < dictionaryCount + (random.Next(2) == 0 ? random.Next(dictionaryCountRandomRange) : -random.Next(dictionaryCountRandomRange)); i++) { var dictionary = new Dictionary { Name = $"{i}_{user.UserName}_Dictionary", Description = loremIpsum.Substring(random.Next(loremIpsum.Length / 3)), IsPublic = random.Next(2) == 0, IsFastAccessible = random.Next(3) != 2 }; dictionaries.Add(dictionary); context.Add(dictionary); } } else { dictionaries = await context.UserDictionaries.Include(ud => ud.Dictionary) .ThenInclude(d => d.Translations) .ThenInclude(t => t.AttributeValues) .Where(ud => ud.UserId == user.Id && ud.Type == UserType.owner) .Select(ud => ud.Dictionary) .ToListAsync(); } foreach (var dictionary in dictionaries) { var translations = new List <Translation>(); if (!dictionary.Translations.Any()) { for (int i = 0; i < translationCount + (random.Next(2) == 0 ? random.Next(translationCountRandomRange) : -random.Next(translationCountRandomRange)); i++) { var idx1 = random.Next(loremIpsum.Length - 6); var idx2 = random.Next(loremIpsum.Length - 6); var translation = new Translation { Original = loremIpsum.CustomSubstring(idx1, 6, stringRemoves), Translated = loremIpsum.CustomSubstring(idx2, 6, stringRemoves), Color = -13615201, Dictionary = dictionary }; translations.Add(translation); context.Add(translation); } } else { translations = dictionary.Translations.ToList(); } foreach (var traslation in translations) { if (!traslation.AttributeValues.Any()) { for (int i = 0; i < attributeValueCount + (random.Next(2) == 0 ? random.Next(attributeValueCountRandomRange) : -random.Next(attributeValueCountRandomRange)); i++) { var attribute = attributes.ElementAt(random.Next(attributes.Count)); var idx = random.Next(loremIpsum.Length - 6); var attributeValue = new AttributeValue(); if (attribute.Type == AttributeType.spinner && attribute.AttributeParameters.Any()) { var attributeParameters = attribute.AttributeParameters; attributeValue = new AttributeValue { Value = attributeParameters.ElementAt(random.Next(attributeParameters.Count)).Value, Translation = traslation, Attribute = attribute }; } else { attributeValue = new AttributeValue { Value = attribute.Type == AttributeType.text ? loremIpsum.CustomSubstring(idx, 6, stringRemoves) : random.Next(2) == 0 ? "true" : "false", Translation = traslation, Attribute = attribute }; } context.Add(attributeValue); } } } if (!context.DictionaryLanguages.Where(dl => dl.DictionaryId == dictionary.Id).Any()) { int firstLanguage = random.Next(languages.Count); context.Add(new DictionaryLanguage { Type = LanguageType.source, Dictionary = dictionary, Language = languages.ElementAt(firstLanguage) }); int secondLanguage; do { secondLanguage = random.Next(languages.Count); }while (firstLanguage == secondLanguage); context.Add(new DictionaryLanguage { Type = LanguageType.destination, Dictionary = dictionary, Language = languages.ElementAt(secondLanguage) }); } if (!context.UserDictionaries.Where(ud => ud.Type == UserType.owner && ud.UserId == user.Id && ud.DictionaryId == dictionary.Id) .Any()) { context.Add(new UserDictionary { Type = UserType.owner, Dictionary = dictionary, User = user }); } } await context.SaveChangesAsync(); } foreach (var user in await context.Users.Include(u => u.UserDictionaries).ToListAsync()) { if (!user.UserDictionaries.Any(ud => ud.Type == UserType.viewer)) { var publicDictionaries = await context.UserDictionaries .Include(ud => ud.Dictionary) .Where(ud => !ud.Dictionary .UserDictionaries .Any(ud => ud.UserId == user.Id && ud.Type == UserType.owner) && ud.Dictionary.IsPublic) .Select(ud => ud.Dictionary) .ToListAsync(); if (publicDictionaries.Count >= viewerCount) { for (int i = 0; i < viewerCount; i++) { var publicDictionary = publicDictionaries.ElementAt(random.Next(publicDictionaries.Count)); context.Add(new UserDictionary { Type = UserType.viewer, Dictionary = publicDictionary, User = user }); publicDictionaries.Remove(publicDictionary); } } } } await context.SaveChangesAsync(); } }
internal static AJH.CMS.Core.Entities.Attribute GetAttribute(int id, int languageID) { AJH.CMS.Core.Entities.Attribute attribute = null; using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString)) { SqlCommand sqlCommand = new SqlCommand(SN_ATTRIBUTE_GET_BY_ID, sqlConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter sqlParameter = null; sqlParameter = new SqlParameter(PN_ATTRIBUTE_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = id; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(ECommerceDataMapperBase.PN_MODULE_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = (int)CMSEnums.ECommerceModule.Attribute; sqlCommand.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter(ECommerceDataMapperBase.PN_ECO_LAN_LAN_ID, System.Data.SqlDbType.Int); sqlParameter.Direction = System.Data.ParameterDirection.Input; sqlParameter.Value = languageID; sqlCommand.Parameters.Add(sqlParameter); sqlCommand.Connection.Open(); using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)) { while (sqlDataReader.Read()) { attribute = new Entities.Attribute(); FillFromReader(attribute, sqlDataReader); } sqlDataReader.Close(); sqlCommand.Connection.Close(); } } return attribute; }
public static IList <Subset> CreateSubsets(this IList <Row> rows, Row currentParserRow, Entities.Attribute decisionAttribute, bool calculate) { IList <Subset> result = new List <Subset>(currentParserRow.Attributes.Count); foreach (Attribute singleAttr in currentParserRow.Attributes) { if (!singleAttr.EqualsByName(decisionAttribute)) { result.Add(new Subset() { Name = singleAttr.Name }); } } foreach (Row singleRow in rows) { for (int i = 0; i < singleRow.Attributes.Count; i++) { if (singleRow.Attributes[i].EqualsByName(currentParserRow.Attributes[i]) && !singleRow.Attributes[i].EqualsByName(decisionAttribute)) { if (!singleRow.Attributes[i].EqualsByValue(currentParserRow.Attributes[i])) { result.Where(x => x.Name == singleRow.Attributes[i].Name).First().Rows.Add(singleRow.Name); } } } } if (calculate) { foreach (Subset singleSubset in result) { int diffrentOnDecision = singleSubset.Rows.Count(); int equalOnDecision = 1; foreach (Row singleRow in rows) { if (singleRow.Name != currentParserRow.Name) //should be always true { foreach (Attribute singleAttr in singleRow.Attributes) { if (singleAttr.EqualsByName(decisionAttribute)) { if (singleAttr.EqualsByValue(decisionAttribute)) { equalOnDecision++; } break; } } } } result.Where(x => x.Name == singleSubset.Name).First().Quotient = System.Convert.ToDecimal(diffrentOnDecision) / equalOnDecision; } } return(result); }
public static IList <Row> GetRowsSeparatedByAttribute(this IList <Row> rows, Row currentParserRow, Entities.Attribute decisionAttribute) { List <Candidate> candidates = new List <Candidate>(); Candidate candidate = null; foreach (Row singleRow in rows) { if (singleRow.Name != currentParserRow.Name) { candidate = new Candidate(); candidate.Row = singleRow; for (int i = 0; i < currentParserRow.Attributes.Count; i++) { if (singleRow.Attributes[i].EqualsByName(decisionAttribute)) //we've found our decision attribute { if (!singleRow.Attributes[i].EqualsByValue(decisionAttribute)) { candidate.IsDifferentOnDecision = true; continue; } } if (singleRow.Attributes[i].EqualsByName(currentParserRow.Attributes[i])) //check other attributes { if (singleRow.Attributes[i].EqualsByValue(currentParserRow.Attributes[i]) == false) { candidate.DifferentOnAttributes++; } } } candidates.Add(candidate); } } return(candidates .Where(x => x.IsDifferentOnDecision == true && x.DifferentOnAttributes > 0) .Select(x => x.Row) .ToList()); }