public static bl_ActivityCategory_Result Edit(bl_ActivityCategory info) { using (var metadata = DataAccess.getDesktopMetadata()) { //Get original guest record var qActCat = (from row in metadata.db_ActivityCategory where row.activityCategoryID == info.activityCategoryID select row).FirstOrDefault(); //Check if their is a duplicate var qDuplicate = (from row in metadata.db_ActivityCategory where row.Name.ToLower().Trim() == info.Name.ToLower().Trim() && row.activityCategoryID != info.activityCategoryID select row).FirstOrDefault(); var item = qActCat; if (item == null) { throw new NullReferenceException("No Activity Category found. Refresh Page"); } var duplicate = qDuplicate; if (duplicate == null) { item.Name = info.Name; item.Price = info.Price; metadata.SaveChanges(); var result = new bl_ActivityCategory_Result { hasError = false }; return(result); } else { var result = new bl_ActivityCategory_Result { hasError = true, ErrorText = "Name already exist for another Activity Category" }; return(result); } } }
public static bl_ActivityCategory_Result Add(bl_ActivityCategory info) { using (var metadata = DataAccess.getDesktopMetadata()) { var qDuplicate = (from row in metadata.db_ActivityCategory where row.Name.ToLower().Trim() == info.Name.ToLower().Trim() select row).FirstOrDefault(); if (qDuplicate == null) { var newActivityCategory = new db_ActivityCategory { Name = info.Name, Price = info.Price }; metadata.db_ActivityCategory.Add(newActivityCategory); metadata.SaveChanges(); var result = new bl_ActivityCategory_Result { hasError = false, }; return(result); } else { var result = new bl_ActivityCategory_Result { hasError = true, ErrorText = "Name already exist for another Activity" }; return(result); } } }