public void Update(Category item) { category = GetById(item.Id); if (category == null) { throw new ArgumentNullException("Spending Category not found"); } defaultCategory = defaultCategoryRepo.GetByName(category); if (defaultCategory != null) { throw new Exception("You cannot change Default Category"); } category.Name = item.Name; category.IsActive = true; using (var context = new BudgetWatcherContext()) { context.Categories.Attach(category); context.Entry(category).State = EntityState.Modified; context.SaveChanges(); } }
private void ComboCategories_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (!DefaultCategory.Equals(ComboCategories.SelectedItem.ToString())) { IsDirty = true; } }
public void GetById_Test() { item.Id = 1; item.Name = "Car"; item = defaultCategoryRepo.GetById(item.Id); Assert.IsNotNull(item); }
public ActionResult DeleteConfirmed(int id) { DefaultCategory defaultCategory = db.DefaultCategories.Find(id); db.DefaultCategories.Remove(defaultCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public DefaultCategory GetByName(Category item) { using (var context = new BudgetWatcherContext()) { defaultCategory = context.DefaultCategories.FirstOrDefault(x => x.Name == item.Name); } return(defaultCategory); }
public DefaultCategory GetById(int id) { using (var context = new BudgetWatcherContext()) { defaultCategory = context.DefaultCategories.FirstOrDefault(x => x.Id == id); } return(defaultCategory); }
public static DefaultCategoryType GetCategoryType(DefaultCategory category) { // lazy loading if (CategoryTypeMapping == null) { CategoryTypeMapping = GetCategoryTypeMapping(); } return(CategoryTypeMapping[category]); }
public ActionResult Edit([Bind(Include = "Id,Name")] DefaultCategory defaultCategory) { if (ModelState.IsValid) { db.Entry(defaultCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(defaultCategory)); }
public ActionResult Create([Bind(Include = "Id,Name")] DefaultCategory defaultCategory) { if (ModelState.IsValid) { db.DefaultCategories.Add(defaultCategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(defaultCategory)); }
// GET: DefaultCategories/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DefaultCategory defaultCategory = db.DefaultCategories.Find(id); if (defaultCategory == null) { return(HttpNotFound()); } return(View(defaultCategory)); }
private static void CreateCategory( IDataContext dataContext, DefaultCategory defaultCategory, User user) { var category = new Category { Title = defaultCategory.Title, Type = defaultCategory.Type, User = user }; dataContext.Categories.Add(category); }
private static DefaultCategory TraverseCategory( XElement element, CategoryType type) { var title = element.Attribute("title"); if ((title == null) || string.IsNullOrWhiteSpace(title.Value)) { return(null); } var category = new DefaultCategory { Title = title.Value, Type = type, }; return(category); }
public void Add(Category item) { defaultCategory = defaultCategoryRepo.GetByName(item); if (defaultCategory != null) { item.DefaultCategories.Add(defaultCategory); } else { item.DefaultCategories.Add(null); } category.Name = item.Name; category.IsActive = true; category.IsChosen = item.IsChosen; using (var context = new BudgetWatcherContext()) { context.Categories.Add(category); context.SaveChanges(); } }
private static DefaultCategory TraverseCategory( XElement element, CategoryType type) { var title = element.Attribute("title"); if ((title == null) || string.IsNullOrWhiteSpace(title.Value)) { return null; } var category = new DefaultCategory { Title = title.Value, Type = type, }; return category; }
public void Update(DefaultCategory item) { throw new NotImplementedException(); }
private static ClassInfo GetClassInfo(Type typeClass, Dictionary <string, ClassInfo> allClasses, Dictionary <string, StructInfo> allStructs, Dictionary <string, EnumInfo> allEnums) { var res = new ClassInfo(); res.FullName = typeClass.FullName; res.Name = typeClass.Name; res.IsAbstract = typeClass.IsAbstract; Type super = typeClass.BaseType; if (super != null && super.FullName != "System.Object" && super.FullName != "Mediator.Util.ModelObject") { res.BaseClassName = super.FullName; } object defaultObject = Activator.CreateInstance(typeClass); Type tIModelObject = typeof(IModelObject); Type tIModelObjectEnum = typeof(IEnumerable <IModelObject>); PropertyInfo[] properties = typeClass.GetProperties(BindingFlags.Instance | BindingFlags.Public); DefaultCategory defaultCategory = typeClass.GetCustomAttribute <DefaultCategory>(); IdPrefix idPrefix = typeClass.GetCustomAttribute <IdPrefix>(); if (idPrefix != null) { res.IdPrefix = idPrefix.Value; } else { res.IdPrefix = typeClass.Name; } foreach (PropertyInfo p in properties) { Type t = p.PropertyType; bool browseable = p.GetCustomAttribute <Browseable>() != null; if (tIModelObject.IsAssignableFrom(t)) { if (!allClasses.ContainsKey(t.FullName)) { allClasses[t.FullName] = new ClassInfo(); allClasses[t.FullName] = GetClassInfo(t, allClasses, allStructs, allEnums); } res.ObjectMember.Add(new ObjectMember(p.Name, t.FullName, Dimension.Scalar, browseable)); } else if (t.IsGenericType && tIModelObjectEnum.IsAssignableFrom(t)) { t = t.GetGenericArguments()[0]; if (!allClasses.ContainsKey(t.FullName)) { allClasses[t.FullName] = new ClassInfo(); allClasses[t.FullName] = GetClassInfo(t, allClasses, allStructs, allEnums); } res.ObjectMember.Add(new ObjectMember(p.Name, t.FullName, Dimension.Array, browseable)); } else // SimpleMember { Dimension dim = GetDimensionFromPropertyType(t); if (t.IsGenericType) // Nullable or List { t = t.GetGenericArguments()[0]; } else if (t.IsArray) { t = t.GetElementType(); } DataType type = DataValue.TypeToDataType(t); string typeConstraints = ""; if (type == DataType.Enum || type == DataType.Struct) { typeConstraints = t.FullName; } if (type == DataType.Struct) { if (!allStructs.ContainsKey(t.FullName)) { allStructs[t.FullName] = new StructInfo(); allStructs[t.FullName] = GetStructInfo(t, allStructs, allEnums); } } else if (type == DataType.Enum) { if (!allEnums.ContainsKey(t.FullName)) { allEnums[t.FullName] = GetEnumInfo(t); } } object value = p.GetValue(defaultObject, null); DataValue?defaultValue = null; if (value != null) { defaultValue = DataValue.FromObject(value); } Category category = p.GetCustomAttribute <Category>(); string cat = category == null ? (defaultCategory == null ? "" : defaultCategory.Name) : category.Name; res.SimpleMember.Add(new SimpleMember(p.Name, type, typeConstraints, dim, defaultValue, browseable, cat)); } } return(res); }